V
V
Vlad Tanashchuk2020-06-20 21:06:09
Python
Vlad Tanashchuk, 2020-06-20 21:06:09

How to make a separate list for each VK conversation?

I am doing a user blocking command and it is necessary that for each conversation there is a list that contains all blocked users and all IDs of the list must have their own line in the text file where they are saved.
I planned to do it through a dictionary, but it didn't work out:

bans[peer_id] = ban_list = []
bans[peer_id] = ban_list = ban_list.append(reply)
with open('bans.txt','w') as f:
      for key,val in bans.items():
         f.write('{}:{}\n'.format(key,val))

This is how the text file with IDs should look like:
{123456789:
[12345678,
12345678,
123456789,
123456789]}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-06-20
@Xaeruz

What are you doing these double assignments for? Is it really necessary?
https://docs.python.org/3/library/json.html#json.dump

G
Guerro69, 2020-06-20
@Guerro69

Why keep locks in notepad?
It is better and more convenient to do this in a database.
sqlite3, pymysql...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question