这是我读取存在的.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
尝试:确保您的路径中有一个名为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')