directories problem

L

Lowell Kirsh

I'm trying to write a script in python to run several other python
scripts using os.system(scriptName). Many of those other scripts have
lines in them which look something like:
doSomething('config.txt')
where config.txt is a file in the same directory as scriptName. When I
run scriptName from its own directory, it is able to find config.txt.
But when I run scriptName from another directory, it can't find the file
because it's looking in the directory of the script which called it
rather than its own directory. Is there any way around this?

Lowell
 
D

Dan Perl

I'm not sure whether this is what Lowell is looking for, but I've been
looking at a similar problem and I would also like to see a solution for
that: can a python script know its own full path name?

Dan
 
P

Peter Hansen

Dan said:
I'm not sure whether this is what Lowell is looking for, but I've been
looking at a similar problem and I would also like to see a solution for
that: can a python script know its own full path name?

See near the end of this thread:
http://groups.google.ca/[email protected]

Also note that scripts other than the main one can do it even more
easily: __file__, or if that's not always an absolute path,
os.path.abspath(__file__).

-Peter
 
D

Dan Perl

Many thanks, Peter! Just like someone in the thread you are mentioning, I
have to go now and change a few scripts that I have.

And I guess that should give a solution for Lowell also. In each script
that's called with os.system( ), get the path of the script (use
os.path.split) and append the 'config.txt' file (use os.path.join).

Dan
 
L

Lowell Kirsh

Thanks Peter! I'm eager to try this out. It seems like a much cleaner
solution than all the other options I've been considering.

Lowell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top