未定义NamError“ tmpdir”

问题描述 投票:-1回答:1

这是我读取存在的.txt文件的函数。

    def func(tmpdir, file_name):
        full_name = tmpdir/ file_name
        with openFile(filename) as p:
            p.readlines()
        return full_name
    func(tmpdir,'file.txt')

和我的.txt文件已经存在,就像这样。

Some lines that need to print after running the function.

而且我遇到了这种错误。

NameError: name 'tmpdir' is not defined
python python-3.x temporary-files temporary-directory
1个回答
0
投票

尝试:确保您的路径中有一个名为tmpdir的文件夹,其中有一个名为file.txt的文件]

def func(tmpdir, file_name):
    full_name = tmpdir + "/" + file_name
    with openFile(full_name) as p:
        p.readlines()
   return full_name
func("tmpdir",'file.txt')
© www.soinside.com 2019 - 2024. All rights reserved.