I am trying to create multiple json files in for loop, I am trying below, but i am getting error below
OSError: [Errno 22] Invalid argument: 'c:\\csv\x0bolume_current_{vol_size}.json'
What I tried:
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=(',', ': '))
as i get multiple volume size values for example 8, 2 in main loop i need to create a json for each size as one file..like volumen_current_8.json volume_current_2.json like that... anyhelp appreciated.
You are not mentioning the right key for vol_size
.
I am assuming the storage_info
as list
of multiple dict
.
You can do like this:
storage_info = [{"VolumeType": vol_type,"Size": vol_size,"InstanceId": inst_id,"Encrypted": encryption_status,"AliasName": alias_name}, {"VolumeType": vol_type_one,"Size": vol_size_one,"InstanceId": inst_id_one,"Encrypted": encryption_status_one,"AliasName": alias_name_one}]
for s in storage_info:
filename = 'c:\csv\\volume_current_{}.json'.format(s['Size'])
with open(filename, "w") as f:
json.dump(storage_info, f, indent=4, separators=(',', ': '))
If your storage_info
is dict
itself, then you have to do like this for every storage_info
you get:
storage_info = {"VolumeType": vol_type,"Size": vol_size,"InstanceId": inst_id,"Encrypted": encryption_status,"AliasName": alias_name}
filename = 'c:\csv\\volume_current_{}.json'.format(storage_info['Size'])
with open(filename, "w") as f:
json.dump(storage_info, f, indent=4, separators=(',', ': '))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments