Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-24 Thread kakada
learner404 wrote: > It works great, thanks very much to the three of you for these > light-speed answers ... I love this list ! > > Wesley, I've just pre-order your new edition "Core Python programming" > on amazon France, it looks great. :) > > Thanks I love this list too. Da __

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-20 Thread K . Weinert
Hi, try f=file(os.path.join(os.path.expanduser("~")),"myfile"), "r") Kind regards, Karsten. -- Echte DSL-Flatrate dauerhaft für 0,- Euro*! "Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl ___ Tutor maillist - Tutor@python.org http://mail.pytho

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread Alan Gauld
> How can I do to access this file whatever the user is ? > > use os.path.expanduser(path) Neat Wesley, I've never noticed that one before. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread w chun
we are all happy to help. it is really good that you were able to get it working so fast! also, if you want to do any kind of pattern matching with * or ?, then check out the "glob" module. merci! "le livre" does not look that good from here... it is a mess and i have to clean it up before givi

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread Alan Gauld
> The ".myapp.conf" is in the home folder of the user. > ... > obviously I won't know the home user folder name then I wanted to use: > How can I do to access this file whatever the user is ? You can get the user name using getpass.getuser() as described in the OS topic of my tutor under the Secu

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread Paidhi Aiji
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 <[EMAIL PROTECTED]>: > Hello, > > I want to read a configuration fi

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread learner404
It works great, thanks very much to the three of you for these light-speed answers ... I love this list ! Wesley, I've just pre-order your new edition "Core Python programming" on amazon France, it looks great. :) Thanks   On 19/04/06, w chun <[EMAIL PROTECTED]> wrote: >  f=open("~/.myapp.conf",

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread w chun
> 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 ? use os.path.expanduser(path) http://www.python.org/doc/2.4.3/lib/module-os.path.html hope this helps! -- wesley - - - - - - - - - - - -

Re: [Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread Matthew White
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 ([EMAIL PROTECTED]) w

[Tutor] [Linux] open a file in any home "~" ?

2006-04-19 Thread learner404
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","