-2
我必須在python 3.5.2
上做這個編碼挑戰。寫一個程序,讀取hoilday.txt的內容,一次一行
到目前爲止,這裏是我的代碼:
file = open("holiday text",'r')
contents = file.read
print(contents)
file.close()
我必須在python 3.5.2
上做這個編碼挑戰。寫一個程序,讀取hoilday.txt的內容,一次一行
到目前爲止,這裏是我的代碼:
file = open("holiday text",'r')
contents = file.read
print(contents)
file.close()
這應該做的伎倆。請注意,如果文本文件與python不在同一文件夾中(例如C:/ Python35-32),則應該指定整個路徑,除非它是針對您提供文本文件的一些在線挑戰。
file = open("holiday text.txt",'r')
contents = file.read()
file.close()
print(contents)
另一種方法是使用自動打開/關閉相應的文件,像這樣的with
聲明:
with open("holiday text.txt",'r') as file:
contents = file.read()
print(contents)
如果它幫助,請按爲接受的答案的箭頭按鈕。