import module from a different directory
Question: I have a project within which we write scripts for standalone utilities, in
whatever language possible.

These scripts are separated on a team basis; as I work for the feeds team we
keep everything in the feeds folder.

Now we are trying to take our frequently used module to create a sort of
library and for this we are trying to make it generic in nature.

So I created the structure as below and now I'm trying to import modules and
classes from lib but I'm getting error. Below is my dir structure. Can anyone
tell me what I'm doing wrong. Thanks for you help in advance

    
    
    -- /u/user/qa-fo/bin/
            |----- __init__.py
            |----- pythonlib
                   |----- __init__.py
                   |----- linux_util.py
            |----- feeds
                   |----- __init__.py
                   |----- test.py
    

linux_util.py -

    
    
    #!/usr/local/bin/python
    
    def test():
        print "hello test from linux util"
    

test.py

    
    
    #!/usr/local/bin/python
    from bin.pythonlib.linux_util import test
    print execute("date")
    

Here is the output on run

    
    
    python feeds/test.py 
    Traceback (most recent call last):
      File "feeds/test.py", line 6, in <module>
        from bin.pythonlib.linux_util import test
    ImportError: No module named bin.pythonlib.linux_util
    


Answer: You seem to be running this from inside the bin directory. So you'd need to
either have "/u/user/qa-fo/bin/" specifically on your PYTHONPATH, or just
import from pythonlib:

    
    
    from pythonlib.linux_util import test
    

