Python database problem | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

Python database problem

import dbm with dbm.open('contas','c') as contas: contas['0'] = '0' contas['1'] = 'a' contas['2'] = 'b' contas['3'] = 'c' contas['4'] = 'd' def Validation(): user = ent.get() passw = ent2.get() val1 = False val2 = False with dbm.open('contas','c') as contas: for i in contas: print(val1,val2) if user.encode() in contas: val1 = True if passw.encode() in contas[i]: if passw.encode() == '': val2 = False val2 = True print(passw,contas[i]) print(user, passw) if val1 == True and val2 == True: stats['text'] = 'Valid' else: stats['text'] = 'Invalid' #When i clikc the Validation Button my program prints: False False b'a' False True b'b' False True b'c' False True b'd' False True b'' #When i click the button with empty password entry, the program always print the #validatoin password as True, but if i use a strange password(which is not contained in #contas[i]), my pass validation works and print False. Why empty box is valid? print(contas.keys()) [b'1', b'2', b'3', b'4', b'0']

25th Oct 2017, 12:51 PM
Thomas Caio
Thomas Caio - avatar
1 Réponse
+ 1
maybe try "if Len(passw.encode) == 0: val2 = False"
6th Nov 2017, 2:55 PM
stephen barter
stephen barter - avatar