TheShed

Writing to a file in Python

Category: Programming
#Python #filesystem

A fragment for writing to a file in Python:

f = open(filename,'w')
f.write('Hey, I'm saying Hello file! \n')
f.close()

Note that this will overwrite an existing file. Use open(filename,'a') to open in append mode. The Python documentation has details.