[Tutor] PYTHONPATH (Mac OS X)

Dave Angel d at davea.name
Mon Dec 26 13:51:49 CET 2011


On 12/26/2011 07:23 AM, Stayvoid wrote:
>> Simply that python is saying it cannot find the file.
>> So it is probably in a different folder to the one in which the program is running. You need to provide a valid path to the file,
> Those files are in the same folder:
> /Users/Username/Python_modules/
>
> I don't want to write a full path here:
> if __name__ == '__main__':
>     print test('lengthcounter_lutz.py')
>
> How to add this directory to the search path?
Once again, there is no search path for the open() function.  You can 
either supply an absolute name (eg. starting with leading slash), or you 
can supply a path relative to the current directory.  If you're not sure 
what the current directory is, you can fetch it with something like:

import os

print os.path.abspath(os.curdir)

But if you're running the script from the terminal window, it should 
simply be the current directory for that window.  If you're running it 
from some other shell, you'd have to consult that shell's docs.




-- 

DaveA



More information about the Tutor mailing list