Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.34 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Adding data to end of existing file python
  2. try:
  3.     f = open("file.txt", "w")
  4.     try:
  5.         f.write('blah') # Write a string to a file
  6.         f.writelines(lines) # Write a sequence of strings to a file
  7.     finally:
  8.         f.close()
  9. except IOError:
  10.     pass
  11.        
  12. with open('file.txt', 'a') as f:
  13.     f.write('blah')
  14.     f.writelines(lines)