Python doesn't understand %userprofile%

Mike Driscoll kyosohma at
Wed Jun 11 13:47:29 CEST 2008

On Jun 11, 1:58 am, Tim Roberts <t... at> wrote:
> bsag... at 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.
> For the record, the %PERCENT% syntax for looking up an environment variable
> is just a feature of the XP command shell.  It has no meaning to any other
> part of Windows.
> os.environ is the right answer.
> --
> Tim Roberts, t... at
> Providenza & Boekelheide, Inc.

You can use it at the Run command or in Explorer too. If I type
%username% in either place, it opens the following on my XP machine: C:
\Documents and Settings\Mike


More information about the Python-list mailing list