[IPython-user]: IPython install under Win2000

Fernando Perez Fernando.Perez at colorado.edu
Mon Jul 18 20:57:49 CDT 2005

Alan G Isaac wrote:
> On Mon, 18 Jul 2005, Fernando Perez apparently wrote: 
>>Unless someone complains soon, this will go into SVN later today 
> Well my only "complaint" is that you do not start by trying
> os.path.expanduser("~")
> which I took from the discussion to be supported on Un*x,
> many Windows, and Mac OSX.

Not really:

In [3]: os.path.expanduser??
Type:           function
Base Class:     <type 'function'>
String Form:    <function expanduser at 0x400585dc>
Namespace:      Interactive
File:           /usr/lib/python2.3/posixpath.py
Definition:     os.path.expanduser(path)
def expanduser(path):
     """Expand ~ and ~user constructions.  If user or $HOME is unknown,
     do nothing."""
     if not path.startswith('~'):
         return path
     i = path.find('/', 1)
     if i < 0:
         i = len(path)
     if i == 1:
         if 'HOME' not in os.environ:
             import pwd
             userhome = pwd.getpwuid(os.getuid()).pw_dir
             userhome = os.environ['HOME']
         import pwd
             pwent = pwd.getpwnam(path[1:i])
         except KeyError:
             return path
         userhome = pwent.pw_dir
     if userhome.endswith('/'):
         i += 1
     return userhome + path[i:]

It's little more than $HOME, and I very much doubt that it's of a whole lot of 
use under win32, given that if $HOME is undefined, it goes to pwd.getpwuid:

In [5]: pwd.getpwuid??
Type:           builtin_function_or_method
Base Class:     <type 'builtin_function_or_method'>
String Form:    <built-in function getpwuid>
Namespace:      Interactive
     getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,
     Return the password database entry for the given numeric user ID.
     See pwd.__doc__ for more on password database entries.

That sounds about as Unixy as it gets.

In summary, expanduser('~') is not really much better than a plain 
environ['HOME'], so I think something like what I did (which in spirit is 
similar to the myriad solutions other projects seem to have used for the same 
problem) is OK.  If only win32 could default to sensibly honoring $HOME, but I 
won't start ranting again :)

So off to SVN it goes.



More information about the IPython-user mailing list