How to create a file on users XP desktop

drobinow at drobinow at
Sun Oct 7 18:21:31 CEST 2007

On Oct 7, 1:24 am, Scott David Daniels <Scott.Dani... at Acm.Org> wrote:
> goldtech wrote:
> > ... I want the new file's location to be on the user's desktop in
> > a Windows XP environment....
> How about:
>      import os.path
>      handle = open(os.path.expanduser(r'~\DeskTop\somefile.txt'), 'w')
>      ...

 That doesn't work on my system.
 "~" uses the HOME environment variable if set, otherwise uses
HOMEDRIVE and HOMEPATH which is what I posted before.  See Lib/ in a recent source distribution.
 In my case I set HOME to a path without spaces in it, to simplify my
use of Emacs and Cygwin.

More information about the Python-list mailing list