Re: [Tutor] [Linux] open a file in any home "~" ?
by Paidhi Aiji other posts by this author
Apr 19 2006 11:38AM messages near this date
[Tutor] [Linux] open a file in any home "~" ?
|
Re: [Tutor] [Linux] open a file in any home "~" ?
Hi,
You can use expanduser() from os.path for this:
import os.path
homedir = os.path.expanduser('~user1')
file_to_open = os.path.join(homedir, '.myapp.conf')
f = open(file_to_open, 'r')
Regards,
-Markus-
Quoting learner404 <learner404@[...].com> :
> Hello,
>
> I want to read a configuration file from a small python app (user
> preferences).
>
> 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@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Learner404
Paidhi Aiji
K Weinert
Alan Gauld
Alan Gauld
W Chun
Learner404
W Chun
Matthew White
|