import - Python module function not defined -
i trying import module in python script , can't create work. have python script: /home/user/pythonscript/onedir/onescript.py , utilize script directory higher in hierarchy: /home/user/pythonscript/common.py did next @ top of onescript.py:
import sys sys.path.insert(1,'/home/user/pythonscript') import mutual
in common.py file, have function onecconnect, , when seek run onescript.py, uses onecconnect function, next error: nameerror: name 'onecconnect' not defined
anyone can see wrong or forgot do? thanks
make sure there __init__.py
in directories, go /home/user/pythonscript
, run python code there. so:
python onedir/onescript.py
in onescript.py
can do:
from mutual import onecconnect
the rules are:
always run python script highest possible directory (not deepest project). always have total import lines, no relative imports.this keeps problems away.
import module python-3.4
No comments:
Post a Comment