I know that using getpass.getuser()
command, I can get the username, but how can I implement it in the following script automatically? So i want python to find the username and then implement it in the following script itself.
Script: os.path.join('..','Documents and Settings','USERNAME','Desktop'))
(Python Version 2.7 being used)
The easiest way to acquire the password is to ask the user for it: input("Login Password: ") . And if, for some reason, you absolutely need to get the password without the users permission, it won't be as easy as your describing it. That's fine.
Type whoami and press Enter. Your current user name will be displayed.
This function checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns the value of the first one which is set to a non-empty string. If none are set, the login name from the password database is returned on systems which support the pwd module, otherwise, an exception is raised.
os.getlogin()
return the user that is executing the, so it can be:
path = os.path.join('..','Documents and Settings',os.getlogin(),'Desktop')
or, using getpass.getuser()
path = os.path.join('..','Documents and Settings',getpass.getuser(),'Desktop')
If I understand what you asked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With