small question

Ben Hutchings do-not-spam-ben.hutchings at businesswebsoftware.com
Tue Mar 18 12:16:22 EST 2003


In article <cf097vcss862rmi5n83gc0rp2dt1mhiea7 at 4ax.com>, Rene Pijlman wrote:
> Ian Bicking:
>>Ali Dada:
>>> how can i force a script to execute in the user's home directory?
> 
>>If you want to go to a home directory of a user that's not the current
>>user, you can use the pwd module, like 
>>  
>>  os.chdir(pwd.getpwnam(username)[5])

Or, perhaps more readably:

    os.chdir(os.path.expanduser('~'+username))

> I think this is a better solution than os.environ['HOME'], even
> for the current user, since HOME is set to the user's home
> directory only by convention. It may be (re)set to anything in
> the execution environment of the script.

If the user shouldn't be allowed to change their home directory by
setting HOME, consider what they can do by setting PYTHONPATH...




More information about the Python-list mailing list