windows and home path

Jerry Hill malaclypse2 at gmail.com
Tue Jan 24 11:05:35 EST 2012


On Tue, Jan 24, 2012 at 9:56 AM, Andrea Crotti
<andrea.crotti.0 at gmail.com> wrote:
> Window never stops to surprise me, I've been banging my head since yesterday
> and only
> now I now what is the problem.
>
> So suppose I have something like
>
> from os import path
> print path.expanduser('~')
>
> If I run it from cmd.exe I get /Users/user, doing the same in an emacs
> eshell buffer I get
> /Users/user/AppData/Roaming.
>
> What sense does it make??
> Is there a way to get always the same variable from python somehow?

The os.path.exanduser() docs (
http://docs.python.org/library/os.path.html#os.path.expanduser ) say
that "On Windows, HOME and USERPROFILE will be used if set, otherwise
a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user
is handled by stripping the last directory component from the created
user path derived above."

So, my guess is that emacs is mangling your HOME environment variable.
 That appears to be confirmed by the emacs documentation here:
http://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html#General-Variables
.

At a guess, you do not have a system-wide HOME environment variable.
When you launch python from the command line, it uses either your
USERPROFILE setting, or is falling back to using HOMEDIRVE and
HOMEPATH.  When you launch emacs, it sees that HOME is not set, and
emacs helpfully sets it for you, to whatever path it thinks is
correct.  That would explain why you see different answers in
different environments.

Does that explain the behavior you're seeing?

-- 
Jerry



More information about the Python-list mailing list