0
Follow
2
View

Python appending new Lists to JSON file with loop

durkwin 注册会员
2023-01-25 03:57

Alright, thanks to the comments below my question I was able to solve the problem.

json_data = []

#GET OLD LIST
if exists('immodata.json'):
    with open ('immodata.json') as file:
     json_data = json.load(json_file)
else:
    with open('immodata.json', 'a') as file:
        print("Created new immodata.json File")

#CREATE THE NEW LIST
new_list = [{'preis': priceList, 'plz': plzList, 'zimmer': roomList, 'wohnflaeche': sqrList} for priceList, plzList, roomList, sqrList in zip(priceList, plzList, roomList, sqrList)]

#ADD THE NEW LIST TO THE OLD
json_data += new_list


with open('immodata.json', 'w') as file:
    json.dump(json_data, file)

I downloaded the file, added the new list to the old one and then wrote this to a new one.

About the Author

Question Info

Publish Time
2023-01-25 03:57
Update Time
2023-01-25 03:57

Related Question

关于#python#的问题,如何解决?

通过将变量除以3,将python pandas中的季度数据转换为月数据

python中的毫秒倒计时计时器

python折线图分析男性消费水平随年龄增长的趋势

筛选带有python条件的嵌套列表

python输入错误回车后 ,只能重新来吗

python爬取音乐

Python Selenium不能再向下滚动用户了

如果没有找到html元素,让Python继续

将Python Function应用程序部署到Azure时出错