[Tutor] PYTHONPATH (Mac OS X)

Dave Angel d at davea.name
Tue Dec 20 03:44:08 CET 2011


On 12/19/2011 08:33 PM, Stayvoid wrote:
>> Please clarify, or expand, or tell us what problem you are having or
>> trying to solve.
> Hi!
>
> I want to have a possibility to import modules from the folder, which
> is not included in the load path.
>
> Example:
>
> module.py
> ---------
> def testfunc(name):
>    file = open(name)
>    return len(file.readlines())
>
> if __name__ == "__main__":
>    print testfunc(module.py)
>
> Code listing (shell):
> python /Users/Username/pythonmodules/module.py
>
> NameError: name 'module.py' is not defined
>
> Kind regards.
>
First rule:  include the complete error message, including the traceback.

Also, make sure you copy/paste the message, not paraphrase or retype it.

Anyway, chances are the error occurs because you didn't have any quotes 
around the filename.  Python is forced to look up the name "module" in 
the global dictionary, and it can't find it.  Of course, the error 
message wouldn't be exactly that.


-- 

DaveA



More information about the Tutor mailing list