Question about import

Frank Millman frank at
Thu Sep 10 09:12:29 CEST 2015

Hi all

My project comprises a number of modules, split into packages. Modules 
frequently need to access the contents of other modules, in the same or in a 
different package. I am getting better at it, but I still occasionally bump 
my head against circular imports, and have to fiddle around until it settles 
down again. Not ideal, I know.

I have just noticed something odd, and I wondered if it might provide a 
solution, or if it is a dangerous sidetrack. Here is a simple example -

    import a.aa
    import b
    def aaa():
        print('in aaa')
    def aaaa():
            print('in aaaa')
    import a
    def bbb():
        print('in bbb')
    def bbbb():
        print('in bbbb')

in aaa
in bbbb
in bbb
in aaaa

The surprising thing is that, within, I just have to say 'import b', 
and I can access '', and the same applies to ''.

That makes me wonder if, in my project, I can import all modules inside 
'', and then just use 'import package_name' inside each module?

Another question - I thought that, because and are in different 
sub-directories, I would have to set them up as packages by adding 
'' to each one, but it works fine without that. What am I 

I am using python 3.4.

Any comments appreciated.

Frank Millman

More information about the Python-list mailing list