我在尝试加载其中一个配置文件时收到错误消息。以下是文件夹结构:Python无法在文件夹树中找到文件
- script.rb
- ROOT_FOLDER
- command_line_interface.py
- 演员
- utils.py
- AZ
- Ç onfig1.txt
- config2.txt
- BZ
- config1.txt
- config2.txt
查询folows:script.rb> command_line_interface.py> utils.py> config2.txt
在script.rb:
IO.popen("./root_folder/command_line_interface.py -arg1 5")
在command_line_interface.py:
if __name__ == '__main__':
sys.path.append(os.path.dirname(sys.argv[0]))
parser = argparse.ArgumentParser(description='Test')
parser.add_argument('-arg1', '--arg1', action='store', type=int, help='Test', dest='arg1')
args = parser.parse_args()
if args.arg1:
utils.run(action)
在utils.py根据动态加载config.txt动作参数[R使用BASE_PATH:
def run(action):
base_path = 'extras/BZ/'
.
.
.
filename = base_path + 'config2.txt'
with open(filename) as f:
result = json.load(f)
IO错误:[错误2]没有这样的文件或目录: '\演员\ BZ \ config2.txt'
它的工作原理是:在Windows里面的提示直接ROOT_FOLDER叫,但是它从script.rb中调用时没有。它需要在两种情况下运行。 有谁知道是什么导致了错误?
\ extras'?你的意思是你得到了一个领先的反斜杠?打印'文件名'并发布值。 –
这是打印文件的名称: extras/BZ/config2.txt –