PEP8 suggests you to use:
with open('test.txt', 'a+') as f:
f.write( "Your new content" )
The with
statement is better because it will ensure you always close the file, even if an exception is raised.
Example adapted from: http://docs.python-guide.org/en/latest/writing/style/#pep-8
solved Create or open file in python [closed]