首页 > 解决方案 > 带有多个文件的 os.path.join 不起作用

问题描述

我需要以下一些帮助,我似乎无法解决这个问题。

我需要用来path.join构建我想要的路径。

base_name = os.path.dirname(__file__)
input_file = apache.log
output_filename = os.path.join(base_name,"test_",input_file)

但我得到/Users/test/Dropbox/Python/apache.log而不是 /Users/test/Dropbox/Python/test_/apache.log我不明白为什么......

谢谢

标签: pythonpython-3.xpath

解决方案


怎么样:

base_name = os.path.dirname(__file__)
input_file = "apache.log"
output_filename = os.path.join(base_name,"test_",input_file)

推荐阅读