fork download
  1. poem = '''\
  2. Programming is fun
  3. When the work is done
  4. if you wanna make your work also fun:
  5. use Python!
  6. '''
  7.  
  8. f = file('poem.txt', 'w') # open for 'w'riting
  9. f.write(poem) # writes the text of the poem to a file
  10. f.close() # close the file
  11.  
  12. f = file('poem.txt') # if no mode is specified, 'r'ead mode is assumed by default
  13. while True:
  14. line = f.readline()
  15. if len(line) == 0: # Zero length indicates EOF
  16. break
  17. print line, # Notice comma to avoid automatic newline added by Python
  18. f.close() # close the file
  19.  
Runtime error #stdin #stdout 0.03s 6352KB
stdin
Standard input is empty
stdout
Standard output is empty