Created
July 31, 2013 14:27
Revisions
-
Joseph Pan revised this gist
Aug 4, 2013 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,9 @@ with open('poem.txt', 'w', encoding="utf-8") as f: # 写模式打开 f.write(poem) # 写文件 with open('poem.txt', encoding="utf-8") as f: # 如果没有提供打开模式, 则默认假设为读模式 while True: line = f.readline() if not line: break print(line, end='') -
Joseph Pan revised this gist
Aug 2, 2013 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,14 +8,12 @@ use Python! ''' with open('poem.txt', 'w', encoding="utf-8") as f: # 写模式打开 f.write(poem) # 写文件 with open('poem.txt', encoding="utf-8") as f # 如果没有提供打开模式, 则默认假设为读模式 while True: line = f.readline() if not line: break print(line, end='') -
Joseph Pan revised this gist
Aug 1, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,4 +18,4 @@ if not line: break print(line, end='') f.close() # 别忘了关闭文件 -
Joseph Pan revised this gist
Aug 1, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,11 +8,11 @@ use Python! ''' f = open('poem.txt', 'w', encoding="utf-8") # 写模式打开 f.write(poem) # 写文件 f.close() # 关闭文件 f = open('poem.txt', encoding="utf-8") # 如果没有提供打开模式, 则默认假设为读模式 while True: line = f.readline() if not line: -
Joseph Pan revised this gist
Aug 1, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ f = open('poem.txt', encoding="utf-8") # 如果没有提供打开模式, 则默认假设为读模式 while True: line = f.readline() if not line: break print(line, end='') f.close() # 别忘了关闭文件 -
Joseph Pan revised this gist
Aug 1, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ f = open('poem.txt', encoding="utf-8") # 如果没有提供打开模式, 则默认假设为读模式 while True: line = f.readline() if not line: # 长度为0代表EOF(注: end of file即文件尾) break print(line, end='') f.close() # 别忘了关闭文件 -
Joseph Pan created this gist
Jul 31, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ #!/usr/bin/python # Filename: file_io.py poem = '''\ Programming is fun When the work is done if you wanna make your work also fun: use Python! ''' f = open('poem.txt', 'w', encoding="utf-8") # 写模式打开 f.write(poem) # 写文件 f.close() # 关闭文件 f = open('poem.txt', encoding="utf-8") # 如果没有提供打开模式, 则默认假设为读模式 while True: line = f.readline() if len(line) == 0: # 长度为0代表EOF(注: end of file即文件尾) break print(line, end='') f.close() # 别忘了关闭文件