如何找到作为参数传递给 Python 脚本的配置文件的位置?
How to find the location of the configuration file passed as argument to Python script?
我觉得这个问题的标题已经足够描述了。
如何找到作为参数传递给 python 脚本的配置文件的位置。
我想创建配置文件的备份,但将其复制到另一个位置。
您可以将当前工作文件夹加入参数路径以获得绝对路径。
import os
import sys
if len(sys.argv) > 1:
full_path = os.path.join(os.getcwd(), sys.argv[1])
print(full_path)
我觉得这个问题的标题已经足够描述了。
如何找到作为参数传递给 python 脚本的配置文件的位置。
我想创建配置文件的备份,但将其复制到另一个位置。
您可以将当前工作文件夹加入参数路径以获得绝对路径。
import os
import sys
if len(sys.argv) > 1:
full_path = os.path.join(os.getcwd(), sys.argv[1])
print(full_path)