Mailing List Archive

os.environ => invalid token
I tried the os.environ['HOME'] statement from the libref. man to get a
string with the home directory.

print os.environ['HOME']

gives : invalid token.

What do I do wrong? How do I get the home directory?


/Peter Thorstenson
os.environ => invalid token [ In reply to ]
[posted & mailed]

On Aug 11, Peter Torstenson blah blah blah:
> I tried the os.environ['HOME'] statement from the libref. man to get a
> string with the home directory.

Are you sure you imported the os module?

>>> import os
>>> print os.environ['HOME']
/home/jeffp

Works fine for me. What OS are you on?

You can also check what python sees as your environment by doing:

>>> import os
>>> for n in os.environ.keys():
... print n + "=" + os.environ[n]

--
jeff pinyan japhy@pobox.com japhy+perl@pobox.com japhy+crap@pobox.com
japhy's little hole in the (fire) wall: http://www.pobox.com/~japhy/
japhy's perl supposit^Wrepository: http://www.pobox.com/~japhy/perl/
The "CRAP" Project: http://www.pobox.com/~japhy/perl/crap/
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
os.environ => invalid token [ In reply to ]
Peter Torstenson wrote:
>
> print os.environ['HOME']
>
> gives : invalid token.

It should work; looks like a parsing problem. Have
you accidentally typed a control character somewhere
in that line? Is your indentation consistent?

--
Greg Ewing, Computer Science Dept, | The address below is not spam-
University of Canterbury, | protected, so as not to waste
Christchurch, New Zealand | the time of Guido van Rossum.
greg@cosc.canterbury.ac.nz