我是编程和python语言的新手.
我知道如何在python中打开文件,但问题是我如何打开文件作为函数的参数?
例:
function(parameter)
Run Code Online (Sandbox Code Playgroud)
这是我写出代码的方式:
def function(file):
with open('file.txt', 'r') as f:
contents = f.readlines()
lines = []
for line in f:
lines.append(line)
print(contents)
Run Code Online (Sandbox Code Playgroud)