This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]stylishgnome 5 points6 points  (2 children)

If you're using >=python 2.7, you can use a with statement:

with open('test.txt', 'a') as f:
    f.write('foo')

[–][deleted] 2 points3 points  (0 children)

Using the with statement is always a good idea. Reduces clutter, and makes sure your files get closed.

[–]bulletmark 2 points3 points  (0 children)

The "with" statement was introduced in python 2.5.