Richard Teasdale
asked on
relative directory python
Hi: I want to read files from the directory beneath that where the python program resides.
This is in windows XP
The code reads for the current directory:
files = [f for f in os.listdir('.') if os.path.isfile(f)]
but I want to read the directory 'import' off the current.
I have tried /import; /import/;./import; and ./import/!
I either get a warning that directory does not exist or the program executes with nothing returned. It does work when I copy the files into the current directory so the program is OK!
The directories and files are stored on a server, the program run from a local PC
Does anybody know how to set a different directory when reading in python?
This is in windows XP
The code reads for the current directory:
files = [f for f in os.listdir('.') if os.path.isfile(f)]
but I want to read the directory 'import' off the current.
I have tried /import; /import/;./import; and ./import/!
I either get a warning that directory does not exist or the program executes with nothing returned. It does work when I copy the files into the current directory so the program is OK!
The directories and files are stored on a server, the program run from a local PC
Does anybody know how to set a different directory when reading in python?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
... should be os.path.dirname(__file__)
thanks pepr. You always get me if I post unverified code ;-)
Oh, no! I was just surprised the function exits (and searched in the doc). It looked a bit strange to me ;)
ASKER