Problem with modules refering to each other

Karl Putland kperacles at geocities.com
Sun Aug 8 10:18:26 EDT 1999


Phil,

I agree with Klaus.  About the imports. one thing to do might be to refer to the other module only from def or class statements.

Phil Hunt <philh at vision25.demon.co.uk> wrote in message news:934075710snz at vision25.demon.co.uk...
> I have two python modules, both of which need to refer to classes 
> defined in the other one. How do I do this? 
> 
> I am currently putting at the start of each module a line of the form:
> 
>    from theOtherModule import *
> 
> However, this is not working. My modules -- greatly simplified -- look
> like this:
> 
>    #bak.py
>    from hhh import *
>    ti = AnHhhClass()
>    print ti

#bak.py
from hhh import *

def make_ti()
    ti = AnHhhClass()
    print "inside make_ti():", ti
    return ti    # If you need it outside of this function

# self test
if __name__ == '__main__':
    ti = make_ti()
    print "outside at module:", ti
 
> and:
> 
>    #hhh.py
>    from bak import *
>    class AnHhhClass: pass
> 
> When I run ``python bak.py'', I get the error message 
> ``NameError: AnHhhClass''.
> 
> -- 
> Phil Hunt....philh at vision25.demon.co.uk
> 

Karl Putland
kperacles at geocities.com





More information about the Python-list mailing list