Newbie - circular import problem

Chetan Gadgil cgadgil_list at cxoindia.dnsalias.com
Tue Feb 24 05:35:19 EST 2004


Try:

> --b.py--
import a
class ClassB(a.ClassA):
    def __init__(self):
        print 'ClassB'
 




`I know what you're thinking about,' said Tweedledum: `but it isn't so,
nohow.'
    -- Lewis Carroll, Through the Looking Glass


> -----Original Message-----
> From: 
> python-list-bounces+cgadgil_list=cxoindia.dnsalias.com at python.
> org 
> [mailto:python-list-bounces+cgadgil_list=cxoindia.dnsalias.com
> @python.org] On Behalf Of sw
> Sent: Tuesday, February 24, 2004 3:46 PM
> To: python-list at python.org
> Subject: Newbie - circular import problem
> 
> 
> Can you give me some pointers on resolving this circular 
> inclusion? I've got 
> two classes, in two files:
> 
> --a.py--
> import b
> class ClassA:
>     def __init__(self):
>         print 'ClassA'
> 
> --b.py--
> import a
> class ClassB(ClassA):
>     def __init__(self):
>         print 'ClassB'
>  
> If I try to access ClassB (for example, by firing up python 
> and importing b), I get the error:
> 
>   File "b.py", line 2, in ?
>     class ClassB(ClassA):
>     NameError: name 'ClassA' is not defined
> 
> Could someone explain what is going wrong here? I'm still 
> getting up to speed with python, but, to me, this looks like 
> the import of b is occuring before ClassA has been defined. 
> Is that right? How can I correct this, apart from 
> amalgamating the two into a single file?
> 
> Many thanks for any guidance.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list