あなたはこれをたくさん単純化することができます
def removeUserFromSessionDatabase(self, user):
return self.users.pop(user,False)
また
def removeUserFromSessionDatabase(self, user):
if self.users.pop(user,False):
print "%s was deleted from group"
else:
print "%s is not in group"
また
def removeUserFromSessionDatabase(self, user):
userData = self.users.pop(user,False):
if userData:
#do Something
else:
#do something else
または最後に
def removeUserFromSessionDatabase(self, user):
try:userData = self.users.pop(user):
except KeyError:
#user does not exist in dict
pass
print "Deleted {0}:{1} From List".format((user,userData))
どうやら(デンランごとに、私はそれを信じています) del
使用しても問題ありません
def removeUserFromSessionDatabase(self, user):
try:
del self.users[user]
print "Removed user"
except KeyError:
print "User does not exist"
def alt_removeUserFromSessionDatabase(self, user):
if user in self.users
del self.users[user]
print "Removed user"
else:
print "User does not exist"