100 % portable ?

Ben Last ben at benlast.com
Wed Aug 25 04:40:56 EDT 2004


>From the Quasi source:
    def getHome(self):
        """Return the path to the home directory - a cross-platform
        equivalent of "~"."""
        #We try this on all OS's, since HOME is not set for plain vanilla
        #WIN32, but *is* set under Cygwin.  Rather than use an exception,
        #and suffer the hit every time on Windows, use a key test.
        #NOTE; this is also done on Windows because I've had reports of
people
        #explicitly setting HOME for some level of Posix-compatibility, so
we
        #allow it to override the HOMEDRIVE/HOMEPATH here.
        if os.environ.has_key('HOME'):
            return os.environ['HOME']

        #try the windows alternative; if HOME failed and we're under
        #some nature of win32 environment.
        if sys.platform == "win32":
            try:
                #we expect this to succeed.
                return os.environ['HOMEDRIVE']+os.environ['HOMEPATH']
            except KeyError:
                pass

        #This is the default... no more we can really do.
        return "."

I don't support Quasi under any Windows OS lower than 2k, so I freely admit
to not having tested it on 95, 98 or Me :)

ben

> -----Original Message-----
> From: python-list-bounces+ben=benlast.com at python.org
> [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of Dave
> Cook
> Sent: 23 August 2004 18:47
> To: python-list at python.org
> Subject: Re: 100 % portable ?
>
>
> In article <2otm5mFed44hU1 at uni-berlin.de>, Bernd Kaiser wrote:
>
> > You can use os.environ["HOME"], this will return the user's home dir.
>
> Doesn't work in win9x AFAIK.  I do notice that some people are starting to
> require XP for their apps.




More information about the Python-list mailing list