python - 在python Centos8中实现json
问题描述
我有一个 .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
推荐阅读
- flutter - 在 pubspec.yaml 中检测到错误:第 49 行第 13 列错误:此处不允许映射值。你之前错过了一个冒号吗?╷ 49 │ 字体:│ ^
- mysql - 无法对包含 MySql 中的聚合或子查询的表达式执行聚合函数
- ssh - Spark 会话运行但从属服务器不会运行
- function - 如何使用 matlab 函数的设置输出复杂的绘图
- python - 为什么 Deep Learning with TensorFlow 提供的代码结果与其书中的快照不同
- sql - 将另一个表中的逐行值转换为字符串并将其插入到 SQL 中的 NOT IN 子句中
- javascript - 返回数组的子数组中最大数的数组
- selenium - 如何使用 selenium testng 代码对多个 testng 方法使用 dataProvider
- html - Django - 自定义表单,特别是字段的外观
- react-native - 意外的令牌,在 React Native 中应为“=>”