On 20/12/11 01:33, Stayvoid wrote:
I want to have a possibility to import modules from the folder, which
is not included in the load path.
The code and error below has nothing to do with importing modules or the
PYTHONPATH value.
module.py
---------
def testfunc(name):
file = open(name)
return len(file.readlines())
if __name__ == "__main__":
print testfunc(module.py)
This is simply opening the file module.py as any other file.
It does not invoke Pythons import mechanism.
Code listing (shell):
python /Users/Username/pythonmodules/module.py
NameError: name 'module.py' is not defined
Please post the full error text not a summary.
But in this case it isc complaining about the favct that you have not
put quotes around the filename so it thinks module.py is a variable, but
when it looks for it, it is not defined.
BTW To set PYTHONPATH in a MacOSX environment you have to edit your
.profile or .bash_profile (I can never remember which!) and add a line like
export PYTHONPATH=/path/to/your/modules:/another/module/path/here
HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor