On Tue, 17 Feb 2009 00:41:26 -0000, Noam Aigerman <no...@answers.com> wrote:

Hi,

What is the best way to reference a non-python file's path from inside
python ?

Until now, I (stupidly) had such lines  as:


theFile=open('../somefile.txt')


in my  python files. Now I moved my python files to another dir, and all
those relative filenames broke.

On the other hand, the solution of writing the full path of each
resource isn't welcome either, as we're working from a SVN repository
and we sometimes checkout to different dir's. I am sure there is a third
way which didn't occur to me...

What do you recommend?

It rather depends on what the files are.  Some (clearly not this) will
be best coded as absolute paths.  Probably your best bet otherwise is
to set an environment variable outside Python to point to the appropriate
directory, and read it out of the os.environ dictionary.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to