我有一个修改json文件的.py脚本。但是,我要做的是加载一个json文件,然后用我的代码修改它。我得到的是下一个现象:
with open('example.json', 'r+') as file:
dictionary_data = json.load(file)
.
.(code)
.
.
.
new_file = open("modify.json", "w") 我正在尝试这样的操作,但在CentOs8中遇到了下一个错误
with open(str(sys.argv[1:]), 'r+') as file:
dictionary_data = json.load(file)Traceback (most recent call last):
File "main.py", line 12, in <module>
with open(str(sys.argv[1:]), 'r+') as file:
FileNotFoundError: [Errno 2] No such file or directory: "['helloWorld.json']"
The HelloWorld file is in the same directory as the main.py有什么解决方案可以自动化json文件吗?因此,当我使用命令python3 main.py example.py helloWorld.json从该helloWorld.json文件生成modify.json时
我正在使用Centos8,文件的路径是/root
提前感谢!
发布于 2020-12-14 21:22:28
您的str(sys.argv[1:])是"['helloWorld.json']",它不是文件。尝试使用:
with open(str(sys.argv[1]), 'r+') as file: # for example.json
with open(str(sys.argv[2]), 'r+') as file: # for helloworld.jsonhttps://stackoverflow.com/questions/65289429
复制相似问题