Link to home
Start Free TrialLog in
Avatar of Richard Teasdale
Richard TeasdaleFlag for United Kingdom of Great Britain and Northern Ireland

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?
ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Teasdale

ASKER

Thank you very much!
Avatar of pepr
pepr

... 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 ;)