Aug-22-2020, 07:16 PM
Good afternoon Python community,
I am practicing my Python skills by working on a log-in/registration script that asks if you are currently registered. If Y for 'Yes', then it runs the user through a log in validator. If 'No' then it runs the user through a sign-up form that validates each input field, and stores it into a dictionary
My problem occurs when the user is asked to update a field. In a perfect world, the updated information will replace the appropriate dictionary key/value. However, I have not wrapped my finger around how exactly can I go about doing this. The original program is about 140 lines long, so I isolated the problem to 14 lines in order for you to see what I'm talking about:
I am practicing my Python skills by working on a log-in/registration script that asks if you are currently registered. If Y for 'Yes', then it runs the user through a log in validator. If 'No' then it runs the user through a sign-up form that validates each input field, and stores it into a dictionary
userBase
. At the end of the sign-up form, the program lists out all of the fields that were filled in to verify if the information is correct. If Y for "Yes" the program exits. If "N" for no, the program asks the user to choose which field they want to update, and re-prompts the field for them to update the selected information. This will loop until the user chooses Y for "Yes", and the program will exit. My problem occurs when the user is asked to update a field. In a perfect world, the updated information will replace the appropriate dictionary key/value. However, I have not wrapped my finger around how exactly can I go about doing this. The original program is about 140 lines long, so I isolated the problem to 14 lines in order for you to see what I'm talking about:
import pprint username = input('enter username: ') password = input('Enter a password: ') userBase = dict( user = { username:{'password': password} }) updateUsername = input('Enter in your new username: ') userBase['user'][username] == updateUsername pprint.pprint(userBase)The output that I'm getting is:
Output:enter username: John
Enter in your new username: Jeff
{'user': {'John': {'password':'12345abcde'}}}
The desired output is:Output:enter username: John
Enter in your new username: Jeff
{'user': {'Jeff': {'password':'12345abcde'}}}
I have searched around the internet for strategies on how to replace a dictionary key/value without entering an immutable string value, but nothing has worked for me so far. Is this something that I have to hack? Am I overlooking something that's very simple? 