How to - import code not in current directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • py

    #1

    How to - import code not in current directory

    I have a python script that I want to test/debug. It contains a class
    which extends from some other class which is located in some other
    python file in a different directory.

    For example:

    [script to test]
    c:\python_code\ foo.py

    [needed python files]
    c:\some\other\d irectory\bar.py

    ....so I want to test/debug foo.py, which needs bar.py. foo.py imports
    bar.py ...but in order to test out foo (in the python shell) I normally
    copy bar.py into the same directory as foo.py...but this is painful.
    Is there some way that I can have python know about the directory where
    bar.py is located, like a system variable, etc? If so, how do I set
    that up?

    Thanks.

Working...