small question

Ian Bicking ianb at colorstudy.com
Sun Mar 16 06:14:36 EST 2003


On Sun, 2003-03-16 at 04:25, Ali Dada wrote:
> how can i force a script to execute in the user's home directory?
> if i know that the user is 'foo' i can say 
> >os.chdir('/home/foo')
> but what is a better and more general way?

  os.chdir(os.environ['HOME'])

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])


-- 
Ian Bicking  ianb at colorstudy.com  http://colorstudy.com
4869 N. Talman Ave., Chicago, IL 60625  /  773-275-7241
"There is no flag large enough to cover the shame of 
 killing innocent people" -- Howard Zinn






More information about the Python-list mailing list