- Adding data to end of existing file python
- try:
- f = open("file.txt", "w")
- try:
- f.write('blah') # Write a string to a file
- f.writelines(lines) # Write a sequence of strings to a file
- finally:
- f.close()
- except IOError:
- pass
- with open('file.txt', 'a') as f:
- f.write('blah')
- f.writelines(lines)