Python module function not defined
Question: I am trying to import a module in my python script and I can't make it work.
So I have my python script: /home/user/pythonscript/oneDir/onescript.py And I
would like to use a script that is a directory higher in hierarchy:
/home/user/pythonscript/common.py So I did the following at the top of my
onescript.py:

    
    
    import sys
    sys.path.insert(1,'/home/user/pythonscript')
    import common
    

In my common.py file, I have a function onecConnect, and when I try to run
onescript.py, which uses onecConnect function, I get the following error:
nameError: name 'onecConnect' is not defined

Anyone can see what I do wrong or forgot to do? Thanks


Answer: Make sure there are `__init__.py` in all directories, go to
`/home/user/pythonscript` and run Python code from there. So:

    
    
    python oneDir/onescript.py
    

In `onescript.py` you can do:

    
    
    from common import onecConnect
    

The rules are:

  * Always run a Python script from the highest possible directory (not the deepest into the project).
  * Always have full import lines, no relative imports.

This keeps the problems away.

