Reputation: 736
I'm creating a python application that requires a user to log into a web service. The credentials are passed to the server in a POST request as a json dictionary. In order to avoid unnecessarily saving the password in a variable I figured I would do something like the following:
json.dumps({'username': raw_input('Username: '), 'password': getpass.getpass()})
raw_input
will get called before getpass
?Upvotes: 0
Views: 88
Reputation: 3782
If you want to insure raw_input()
called before getpass()
, I think you should use variables like this:
username = raw_input('Username: ')
passwd = getpass.getpass()
user_dict = {username : passwd}
Use variable will make your code more readable and easy to maintenance or debug.
First, the code will be execute as raw_input('Username: ')
then getpass.getpass()
make a dict at last.
Second, it's more shorter and if your program is small and easy that's a good way .
Third, it's short, kind of pythonic I guess but not good in engineering side.
Upvotes: 2
Reputation: 113948
Upvotes: 3