Finding the path to a file

Mark Daley mark at diversiform.com
Tue Aug 12 02:05:28 CEST 2003


I use registry keys to handle stuff like that.  It also allows more
flexibility for the end user on the install side.  Of course, you may not
care about an end user, if you are the only one useing the program, but then
you would control all of the directory stuff yourself...

I realize this doesn't answer the question directly, but I felt like I
should put my two cents in.

- Mark

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Todd Johnson
Sent: Monday, August 11, 2003 4:12 PM
To: python-list at python.org
Subject: Finding the path to a file


Hey,

I have been working on a program that stores
information for each user in a subdirectory of the
directory in which the script is run. So if my script
is in /home/someuser/myprogram, the config files and
such are in /home/someuser/myprogram/config. Now if I
invoke the interpreter from the same directory as the
script is in I can load and save the files because cwd
points to that directory(I used cwd to get the path
and then add /config to it to get to the proper
directory)

My problem is that if I invoke it with a command like
python /home/someuser/myprogram but I am in
/home/someuser, cwd does not point to the scripts
directory but to the directory the interpreter was
invoked from. This means I don't know how to find the
config files other than making them hard coded to a
certain directory. I don't want to hard code them
however so that the program can be contained in one
directory and easily removed and I also don't want to
have to specify where a user installs the program.

So basically, I want to know how to find the directory
my script is in, even when it is invoked from another
directory. Any help would be greatly appreciated.

Thanks in advance,
Todd A. Johnson

=====
The grace of the Lord Jesus Christ, and the love of God, and the communion
of the Holy Ghost, be with you all. Amen.  II Corinthians 13:14

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

--
http://mail.python.org/mailman/listinfo/python-list







More information about the Python-list mailing list