0

I am doing a simple password manager in python, the user needs to input platform, user and password.

I tryied to fill the csv in case it was because the csv was empty, also i defined both variables as a list.

I keep getting an error while trying to check if the input platform is already in the csv file.

This is the part of the code:

if n=="1": 
        fo=open(reqfile,'r')
        data=csv.reader(fo)
        datatoread=list(data)
        while check==False:
            newline.append(input("introduce platform:").lower)
            for x in range(len(datatoread)-1):
                if newline[0]==datatoread[x[0]]:
                    print("You already setup an username and password for this platform, please change the platform")
                    
                    check=False
                else:
                    check=True

The output when i print(newline) just after the append statement:

[<built-in method lower of str object at 0x037AF680>]

This is where i put the break:

 fo=open(reqfile,'r')
 data=csv.reader(fo)
 datatoread=list(data)
 while check==False:
        newline.append(input("introduce platform:"))
        for x in range(len(datatoread)):
            print(newline)
            print(datatoread)
            if newline[0]==datatoread[x[0]]:
                print("You already setup an username and password for this platform, please change the name of the platform")
                check=False
                newline.pop()
                break
            else:
                check=True
            break

The output is:

['youtube']

[['Platform', 'Username', 'Password']]

Also with the same error

The error:

File "/PassMan.py", line 27, in if newline[0]==datatoread[x[0]]: TypeError: 'int' object is not subscriptable

If you need all the code, there's my github repo: https://github.com/DavidGarciaRicou/PasswordManagerPython

2 Answers2

0

I advise you to use pandas to read and write your CSV file. I believe it will help you to handle this file type.

This answer shows how to check if there is a string inside a pandas dataframe (i.e. your CSV file).

rmmariano
  • 896
  • 1
  • 18
  • 32
0

Thanks everyone for the help.

I resolved the problem with this code, still don't know what i was doing wrong:

    while check==False:
        newline.append(input("Introduce platform:"))
            
        for x in range(0,len(datatoread)):
            platcheck=datatoread[x]
            plattochk=platcheck[0]
            if newline[0]==plattochk:
                print("You already setup an username and password for this platform, please change the name of the platform")
                check=False
                newline.pop()
                break
        try:
            if newline[0]!=plattochk:
                check=True
        except:
            pass
    fo.close
  • yes! :D now im doing it like that haha, thank you a lot, check my github pls pls, if you want and give me your opiniont?, i've been updating it a lot hehe, now im trying to encode and decode the passwords and usernames, its being a nightmare u.U – David Garcia Ricou Sep 09 '20 at 17:55