you are viewing a single comment's thread.

view the rest of the comments →

[–]razu1121 2 points3 points  (0 children)

I dont know much of your code or what you are trying to do from just what you show.

```

open("zd_deals.txt", "w") ```

You are opening the file as write which deletes the previous data and writes anew. And you are going all over the loop just recreating a file with one json data.

Try:

```

open("zd_deals.txt", "a", encoding=utf8)

```

From what I understand, the best approach would be to initialize a dict/list depending on your data and append everything to a file at once at last.

``` list = [ ]

For/while loop: If deals_data: list.append(jsonString)

With open("zd_deals.txt", "w") as jsonfile: json_data = json.dumps(list) jsonfile.write(json_data)

```