use*_*264 -2 python python-3.x
使用Python 3.7时使用read()和open()函数
是否存在记录的原因open()但read()不是?
https://docs.python.org/3.7/library/functions.html
from sys import argv
script, filename = argv
txt = open(filename)
print(f"Here's your file {filename}:")
print(txt.read())
print("Type the filename again:")
file_again = input("> ")
txt_again = open(file_again)
print(txt_again.read())
Run Code Online (Sandbox Code Playgroud)
因为read不是内置的功能,但一个方法的文件对象(*IO*/ *Reader).
你可以找到这样的documetations read方法:io.RawIOBase.read,io.BufferedIOBase.read,io.BufferedReader.read,io.TextIOBase.read,...