No subject
Terry Hancock
hancock at anansispaceworks.com
Thu Jun 9 11:15:38 EDT 2005
On Monday 06 June 2005 01:42 am, Jatinder Singh wrote:
> B and C are subdirectories of Parent Directory A.
> I am executing a file in Directory C which is importing a file f' in directory
> B.
> Now while running python file m getting an error of can't open f'. If I copy f'
> in
> current directory B. then It is running. I want to get rid of that and run the
> programme without copying the other f' files( even .txt also) in the current
> directory. and I have so many files in directory B,otherwise I wou;ld have
> wppended the path while opening the file. I don't want to do it for each file
> and also If i need to change directory structure then also I should change one
> path and able to run the Programme.
So you want to use a relative path then? Have you tried this:
filepath = os.path.join(os.getcwd(), '..', 'C', filename)
f = open(filepath, 'r')
etc.?
It's really quite straightforward to walk up and down directory trees, please
take a closer look at the documentation for os and os.path modules (see
http://www.python.org to find documentation for your version).
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Python-list
mailing list