os.path.join操作系统()只接受一个参数(给定2个)

2024-05-15 01:31:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到python错误: TypeError:join()只接受set_Xpress方法第139行中的一个参数(给定2个),如下所示:

from os import path
from json import load
...
    def set_Xpress(Xpress_number, special_ts, disk, platform, testcase):
        ...
        with open("{0}:\\BBT2\\Configuration\\temporary.tmp".format(disk), "r") as test_conf_file_r:
            test_conf_vocab = load(test_conf_file_r)
        report = path.join(test_conf_vocab["report_dir"], test_conf_vocab["report_name"])
        ...

请帮我弄清楚是什么原因造成的。pythonshell毫无问题地执行它,同样的笔划在这个tmp文件的另一个方法中执行得很好。提前谢谢。在


Tags: path方法fromtestimportreportconfload
3条回答

{a1}接受任意数量的参数。您确定您的path.join实际上正在调用os.path.join?在

path不是os.path模块,它是一个字符串。你在某个地方重新定义了它。在

from os import path  # path is a module, path.join takes many arguments

...

path = '/some/path'  # path is now a string, path.join is a totally
                     # different method, takes a single iterable
...

report = path.join(one, two)   # TypeError, str.join takes one argument

当然os.path.join操作系统()使用了尽可能多的参数,就像有人说您肯定已将路径重新定义为新变量并存储为字符串,因此请小心关于。不过我绝对是这样做的,经过长时间的搜索和尝试,我发现了我的错误。在

相关问题 更多 >

    热门问题