PATH environment variable

Jeffrey Schwab jeff at
Sun Nov 20 15:05:55 CET 2005

mirandacascade at wrote:
> O/S: Win2K
> Vsn of Python:2.4
> Based on a search of other posts in this group, it appears as though
> os.environ['PATH'] is one way to obtain the PATH environment variable.
> My questions:
> 1) is it correct that os.environ['PATH'] contains the PATH environment
> variable?
> 2) are there other ways to obtain the PATH environment variable? if so,
> is one way of obtaining the PATH environment variable preferable to
> another way?

That's the best way because it's portable.  If you didn't have 
os.environ, you might be able to get PATH but reading the output of some 
subprocess, e.g:

	import commands
	path = commands.getoutput('echo $PATH')

More information about the Python-list mailing list