[英]Implement json in python Centos8
我有一個 .py 腳本來修改 json 文件。 但是我正在做的是加載 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
提前致謝!
你的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.json
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.