I have this function in my class:
def removeUserFromSessionDatabase(self, user):
if user in self.users:
for k in self.users.keys():
if k == user:
del self.users[k]
print("Removed")
else:
print("user does not exist")
else:
print "soemthing"
now I always get error at this last else with message: SyntaxError: invalid syntax
where as it should work. users is a dictionary here and there is no other method. Why am I getting this syntax error?
print()as your other ones are.k in self.users.keysinstead of justself.users.pop(user)in fact you can use pop even if the key doesnt exist so you can get rid of that whole ifprintis a function:print("Something")printline, then, not on theelse:statement.