eclipse,python, NameError: name <MyModule> is not defined
Question: I create the following package in eclipse via `PyDev`:

    
    
    class Repository(object):
        '''
        classdocs
        '''
    
        def __init__(self):
            '''
            Constructor
            '''
            print("salaam")
    
    class Materials(Repository):
        '''
        '''
    
        def __init__(self):
            '''
            constructor
            '''
    

My main file is:

    
    
    if __name__ == '__main__':
        pass
    
    import repository;
    
    
    x = Repository();
    

When i run my application, i get the following error:

    
    
    x = Repository();
    
    NameError: name 'Repository' is not defined
    

Of course, i got a warning on importing my module.

I know my import and relation of my main file and my package or eclipse
configuration have problem.

![My <code>dir struct</code> of my
<code>project</code>](http://i.stack.imgur.com/GOwVS.png)


Answer: first of all, when you import like this, you can only refer to your class as
either `repository.Repository` or `repository.repository.Repository`,
depending on the whether you import the module or the package.

second, what you import depends on where eclipse thinks you are. You can check
that with

    
    
    import os
    print(os.pwd)
    

at the top of your main script.

third, if you want to import your package like this, you should put it in your
search path. You can do that by placing it in site-packages, or for instance
by adding

    
    
    import sys
    import os
    sys.path.append(os.path.abspath(__file__))
    

at the top of your main script

additionally, you might want to avoid confusion by giving your module a
different name than the package (or the other way round)

(and a little nitpick: `__init__` is not the constructor, merely an
initializing routine).

