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?
Your indentation could be incorrect, most likely caused by tabs. Run
python -tt scriptname.pyto check.There is otherwise no syntax error in your code that would cause this specific exception, not in the code you’ve given us.