相关疑难解决方法(0)

如何通过python打开文件

我是编程和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)

python function python-3.x

14
推荐指数
1
解决办法
3万
查看次数

标签 统计

function ×1

python ×1

python-3.x ×1