ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] [Linux] open a file in any home "~" ?
by Matthew White other posts by this author
Apr 19 2006 11:13AM messages near this date
Re: [Tutor] [Linux] open a file in any home "~" ? | [Tutor] Some help with properties and accessor functions....
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:

> >> pwd.getpwnam('mtw')
('mtw', 'x', 1000, 1000, ',,,', '/home/mtw', '/bin/bash')

-mtw

On Wed, Apr 19, 2006 at 07:55:14PM +0200, learner404 (learner404@gmail.com) wrote:
>  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


-- 
Matthew White - District Systems Administrator
Tigard/Tualatin School District
503.431.4128

"The greatest thing in this world is not so much where we are, but in
what direction we are moving."   -Oliver Wendell Holmes

_______________________________________________
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved