B
B
blessmemary2020-09-07 19:18:12
Python
blessmemary, 2020-09-07 19:18:12

"Program" for writing and showing passwords in Python, how to fix errors?

Hello.
Task: make a password manager so that you can write and read passwords from a file.
Passwords are in txt file like this:
YaPythoner
vk - Nagibator228
discord - Nagibator1337

code: https://pastebin.com/BsXCZZEy

Gives errors:
IndexError: list assignment index out of range
TypeError: list indices must be integers or slices, not str

THANKS !

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PavelMos, 2020-09-07
@blessmemary

lines = f.readlines()
lines[int(numb)] = name + ' - ' + parol + '\n'

Lines are read into the list of lines, when adding a new password, the program accesses the list by index, which is not there. You cannot take a list x=[1,2,3,9,10] and add a new element to it with the expression x[6]=20 (but you can add new elements to a dictionary, or overwrite a value in a dictionary or list).
Add to list is append or extend.
If passwords are added under numbers, then these numbers must be read, taking into account the fact that the password number may not be equal to the line index.
And it is also desirable to use an environment that shows which line in which place the error is. This condition generally needs to be included in the rules for creating a question on the site.

T
Timur Pokrovsky, 2020-09-07
@Makaroshka007

well, translate the mistakes and everything will become clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question