I'm creating a JSON from some data using append to update the keys because I use some for loop to that.
The model is the following:
for item in met_variables:
for it, csv in enumerate(all_files):
if "prec" in item:
json_data.append(
{
"stationID": station_id,
"lat": lat,
"lng": lng,
"precValue": value
},
)
else:
"irradValue": value ## here is the problem ##
As I depend on the 2 values that are in met_variables, I can't create JSON at once. I need this iteration.
How could I do this?
Your else statement doesn't make sense as written. Are you trying to add the "irradValue" to json_data? if so that would be
for item in met_variables:
for it, csv in enumerate(all_files):
if "prec" in item:
json_data.append(
{
"stationID": station_id,
"lat": lat,
"lng": lng,
"precValue": value
},
)
else:
json_data.append("irradValue": value)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.