text = '''Some random data
'''
# write to data.txt
with open('data.txt', 'w') as f:
f.write(text)
# append to data.txt
with open('data.txt', 'a') as f:
f.write(text)
with open('readme.txt', 'w') as f:
f.write('readme')
Code language: JavaScript (javascript)
file = open("msg.txt", "w")
file.write("my first file
")
file.write("This file
")
file.write("contains three lines
")
file.close()
$ python my_program.py > output.txt