#!/usr/bin/python# Filename: using_file.pypoem = '''/Programming is funWhen the work is doneif you wanna make your work also fun: use Python!'''f = file('poem.txt', 'w') # open for 'w'riting 'w'不追加 'a+'是追加写(貌似) /r/n换行f.write(poem) # write text to filef.close() # close the filef = file('poem.txt')# if no mode is specified, 'r'ead mode is assumed by defaultwhile True: line = f.readline() if len(line) == 0: # Zero length indicates EOF break print line, # Notice comma to avoid automatic newline added by Pythonf.close() # close the file