I provided this answer because Keith’s, while succinct, doesn’t close the file explicitly
with open("log.txt") as infile:
for line in infile:
do_something_with(line)
More Related Contents:
- How does Python 2 compare string and int? Why do lists compare as greater than numbers, and tuples greater than lists?
- What is the best way to remove accents (normalize) in a Python unicode string?
- How to run multiple Python versions on Windows
- How to get string objects instead of Unicode from JSON?
- Taking multiple integers on the same line as input from the user in python
- Match text between two strings with regular expression
- What exactly do “u” and “r” string prefixes do, and what are raw string literals?
- What is the difference between dict.items() and dict.iteritems() in Python2?
- Python unexpected EOF while parsing
- Why does Python print unicode characters when the default encoding is ASCII?
- Why is ” > 0 True in Python 2?
- How to use a multiprocessing.Manager()?
- Converting “yield from” statement to Python 2.7 code
- Using print() (the function version) in Python2.x
- What is the difference between encode/decode?
- Defining “boolness” of a class in python
- How can I get 2.x-like sorting behaviour in Python 3.x?
- How to print a percentage value in python?
- Safest way to convert float to integer in python?
- Python ascii utf unicode
- How to select a directory and store the location using tkinter in Python
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- How to read a CSV file from a URL with Python?
- Command-line input causes SyntaxError
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- SQLite, python, unicode, and non-utf data
- IndentationError: unindent does not match any outer indentation level, although the indentation looks correct
- Python long filename support broken in Windows
- ImportError: DLL load failed: %1 is not a valid Win32 application for Python Matplotlib
- How can I denote unused function arguments?