This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.expandvars sometimes doesn't expand $HOSTNAME
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dougfort, georg.brandl, neurogeek
Priority: normal Keywords:

Created on 2006-02-17 16:03 by dougfort, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg27546 - (view) Author: Doug Fort (dougfort) Date: 2006-02-17 16:03
$ echo "$HOSTNAME"
c0a80165.tipt.aol.com
$ /usr/local/bin/python
Python 2.4.2 (#1, Dec 30 2005, 11:14:42) 
[GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin
Type "help", "copyright", "credits" or "license" for
more information.
>>> import os.path
>>> os.path.expandvars("$HOME")
'/Users/dougfort'
>>> os.path.expandvars("$HOSTNAME")
'$HOSTNAME'
>>> 

arthurformat-d09:arthur$ echo $HOSTNAME
arthurformat-d09.ats.aol.com
arthurformat-d09:arthur$ /cm/tools/bin/python
Python 2.3.4 (#1, Jul 28 2004, 14:55:53) 
[GCC 3.3.1] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import os.path
>>> os.path.expandvars("$HOME")
'/opt/aol/production/arthur'
>>> os.path.expandvars("$HOSTNAME")
'arthurformat-d09.ats.aol.com'
msg27547 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-17 18:13
Logged In: YES 
user_id=1188172

It might be good if you explain what the differences between
the two snippets are, environment-wise.

The first question that comes to mind is: is $HOSTNAME
exported in the first shell?
msg27548 - (view) Author: neurogeek (neurogeek) Date: 2006-02-17 19:20
Logged In: YES 
user_id=1394223

No problem for me in a Gentoo box in python 2.3.4 nor python
2.4.2

Is the problem persistent? could you give some meore info on
this?
msg27549 - (view) Author: Doug Fort (dougfort) Date: 2006-02-17 20:11
Logged In: YES 
user_id=6399

It looks like posixpath.py uses os.environ to resolve
environment variables. That makes sense. On my OS X 10.4
Python 2.4.2, HOSTNAME does not appear in os.environ. There
must be some shell gimmick to resolve it from the command line. 

I originally experienced this error on RedHat Enterprise
Linux. I'm unable to reproduce it in the interpreteer. The
process experiencing the error is launched from our client's
version of init. I suspect it just isn't getting the
HOSTNAME environment variable passed to it.

So in short, os.expandvars works as designed. I apologize
for submitting the bug without checking more throughly.
msg27550 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-17 20:50
Logged In: YES 
user_id=1188172

Closing as requested.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42915
2006-02-17 16:03:07dougfortcreate