我想在Python中使用File.read()函數將文件內容輸出到終端,但繼續收到與我的「.txt」文件內容不匹配的以下輸出。Python的file.read()函數輸出?
Python代碼
from sys import argv
script, input_file = argv
def print_all(f):
print f.read
current_file = open(input_file)
print "Print File contents:\n"
print_all(current_file)
current_file.close()
輸出:
Print File contents:
<built-in method read of file object at 0x1004bd470>
你已經回答了你自己的問題。你只是說你正在嘗試執行「File.read()」,然而在你的代碼中,你執行了「File.read」 – 2012-08-06 14:45:47
+ 1來抵消(在我看來)不合理的downvote。這是一個合法的問題(一個常見的錯誤,特別是如果你來自Ruby背景,括號是可選的)。 – 2012-08-06 14:46:10