Note that this function will error out if the user does not exist. To prevent this, we should use the get method to test whether the user exists. For example, we can do the following:
user = self.users.get(email)
if user:
The get function will return the value at the key if the key is in the dictionary; if the key is not in the dictionary, it will return None. So, if the email is in the users dictionary, then the variable user will have a value; if not, then user will be None, which will make our if statement return False.
Note that our prior implementation would throw a KeyError if the email was not already in the dictionary.
https://github.com/MorneTer/pwp-capstones/blob/04fefad0f4be95b01417d24acbe8c23b5f400dee/Submit/TomeRater.py#L138-L151
Note that this function will error out if the user does not exist. To prevent this, we should use the
get
method to test whether the user exists. For example, we can do the following:The
get
function will return the value at the key if the key is in the dictionary; if the key is not in the dictionary, it will returnNone
. So, if the email is in theusers
dictionary, then the variableuser
will have a value; if not, thenuser
will beNone
, which will make ourif
statement return False.Note that our prior implementation would throw a
KeyError
if the email was not already in the dictionary.