【发布时间】:2020-06-26 11:53:34
【问题描述】:
我正在尝试在 for 循环中创建多个 json 文件,我在下面尝试,但下面出现错误
OSError: [Errno 22] Invalid argument: 'c:\\csv\x0bolume_current_{vol_size}.json'
我尝试了什么:
storage_info =({"VolumeType": vol_type,"Size": vol_size,"InstanceId": inst_id,"Encrypted": encryption_status,"AliasName": alias_name})
for s in storage_info:
filename = 'c:\csv\volume_current_{vol_size}.json'
with open(filename, "w") as f:
json.dump(storage_info, f, indent=4, separators=(',', ': '))
当我在主循环中获得多个卷大小值(例如 8、2)时,我需要为每个大小创建一个 json 作为一个文件..像 volumen_current_8.json volume_current_2.json 这样...任何帮助表示赞赏。
【问题讨论】: