Answer the question
In order to leave comments, you need to log in
How to store a dictionary (nicknames) in Python?
Hello, I wanted to make a nickname system so that each user has their own nickname. I understood how to implement the system, but there was a problem with saving these same nicknames, for this you need a file, here I was already thinking and did not understand how to implement it, I googled, made my options all useless. Please help.
Script to change nickname:
if msg.startswith('%ник'):
nick = msg.lstrip('%ник').strip()
user_id = event.obj["from_id"]
if len(nick) < 3:
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "⚠ | Никнейм слишком короткий.", "random_id": 0})
if len(nick) > 15:
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "⚠ | Никнейм слишком длинный.", "random_id": 0})
else:
users_nick[user_id] = nick
print(users_nick)
#Функция записи в .txt файл.
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "✔ | Никнейм успешно изменён.", "random_id": 0})
Answer the question
In order to leave comments, you need to log in
Have you tried using json . If it doesn't suit you, then read about other ways to store data in python https://docs.python.org/3/library/persistence.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question