Python doesn't understand %userprofile%

drobinow at gmail.com drobinow at gmail.com
Tue Jun 10 20:21:42 CEST 2008


On Jun 10, 2:09 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> bsag... at gmail.com wrote:
> > In xp when I try os.path.getmtime("%userprofile/dir/file%") Python
> > bites back with "cannot find the path specified" Since my script has
> > to run on machines where the username is unspecified I need a fix.
> > Thanks in advance.
> >>> os.path.expanduser("~/dir/file")
>
> 'C:\\Documents and Settings\\Duncan/dir/file'

"~" appears to look first at the HOME environment variable.
That is not necessarily the same as "USERPROFILE". On my machine it is
not.



More information about the Python-list mailing list