PDA

View Full Version : [SOLVED] why python acting like mad in my ubuntu ?!!



prismctg
August 5th, 2012, 01:19 PM
when i type this
os.getenv('USERNAME') it returns None ; so it does not return my username ; i m using ubuntu 12.04

greenpeace
August 5th, 2012, 01:32 PM
when i type this
os.getenv('USERNAME') it returns None ; so it does not return my username ; i m using ubuntu 12.04

if you run this in the terminal on your box, what does it give you?


echo $USERNAME

raja.genupula
August 5th, 2012, 01:32 PM
http://stackoverflow.com/questions/842059/is-there-a-portable-way-to-get-the-current-username-in-python

trent.josephsen
August 5th, 2012, 01:37 PM
USERNAME isn't exported by default, so new programs can't see it. Don't use getenv for this, though.


>>> from getpass import getuser
>>> getuser()
'trent'

prismctg
August 5th, 2012, 01:48 PM
if you run this in the terminal on your box, what does it give you?


echo $USERNAME

it returns nothing ; just blank !!!

prismctg
August 5th, 2012, 01:49 PM
USERNAME isn't exported by default, so new programs can't see it. Don't use getenv for this, though.


>>> from getpass import getuser
>>> getuser()
'trent'

thnx :)

raja.genupula
August 5th, 2012, 01:54 PM
actually command is echo $USER


raja@badfox:~$ echo $USER
raja


Remember : you have to type as USER not user .

trent.josephsen
August 5th, 2012, 02:19 PM
echo $USERNAME works for me (zsh) so I didn't bother to rethink the naming of the variable, but raja.genupula is right, $USER is the variable that you should use for this purpose.