2016-10-01 25 views

回答

0

這應該做的伎倆。請注意,如果文本文件與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) 

如果它幫助,請按爲接受的答案的箭頭按鈕。