Macports sudo expands ~ to /var/root in python

Posted by calavera on Stack Overflow See other posts from Stack Overflow or by calavera
Published on 2011-02-04T02:24:07Z Indexed on 2011/02/04 7:25 UTC
Read the original article Hit count: 498

Filed under:
|
|
|
|

This might be a bit dev-heavy for the site... but here goes.

I installed the macports version of sudo. All is well, except for one thing. Using python 2.6 to expand ~ to the user's home directory results in a different output than the version of sudo that comes with Snow Leopard.

For example consider the following python code:

#expand_home_dir.py
import os

os.path.expanduser('~')

Below are 3 different calls of the code listed above. The first call using sudo is using the Macports version because my $PATH begins with /opt/local/bin:

robert$ python2.6 expand_home_dir.py 
/Users/robert
robert$ sudo python2.6 expand_home_dir.py 
/var/root
robert$ /usr/bin/sudo python2.6 expand_home_dir.py
/Users/robert

Any idea why this is happening?

© Stack Overflow or respective owner

Related posts about osx

Related posts about macports