[Tutor] [Linux] open a file in any home "~" ?
mwhite3 at ttsd.k12.or.us
Wed Apr 19 20:10:50 CEST 2006
os.getenv('HOME') will return the user's home directory as long as that
environment variable is set.
you can also use the pwd module:
('mtw', 'x', 1000, 1000, ',,,', '/home/mtw', '/bin/bash')
On Wed, Apr 19, 2006 at 07:55:14PM +0200, learner404 (learner404 at gmail.com) wrote:
> I want to read a configuration file from a small python app (user
> The ".myapp.conf" is in the home folder of the user.
> if I do:
> f=open("/home/user1/.myapp.conf","r") #it works
> obviously I won't know the home user folder name then I wanted to use:
> f=open("~/.myapp.conf","r") # but it returns a IOError: [Errno 2] No such
> file or directory:
> How can I do to access this file whatever the user is ?
> Thanks for your help.
> Tutor maillist - Tutor at python.org
Matthew White - District Systems Administrator
Tigard/Tualatin School District
"The greatest thing in this world is not so much where we are, but in
what direction we are moving." -Oliver Wendell Holmes
More information about the Tutor