Classes question
Aahz
aahz at pythoncraft.com
Fri Nov 1 23:23:56 EST 2002
In article <20021101045342.GA1737 at ens-lyon.fr>,
Emmanuel Jeandel <E_Jeandel at mail.dotcom.fr> wrote:
>Il est arrivé, un jour, à Aahz d'écrire :
>> In article <20021031205456.GA8006 at ens-lyon.fr>,
>> Emmanuel Jeandel <E_Jeandel at mail.dotcom.fr> wrote:
>>>
>>>I have the following code :
>>>
>>>class A:
>>> def __init__(self):
>>> pass
>>>
>>> def f(self):
>>> self.x = B()
>>>
>>>class B(A):
>>> def __init__(self):
>>> A.__init__(self)
>>>
>>>
>>>I would like to have the class A and the class B in two differents files.
>>>Is it possible ?
>>>I think that it is not directly possible, but if there is a mean with a
>>>small change in the code...
>>
>> Assuming you put the code for A in classA.py, you can make class B work
>> by adding the line
>>
>> from classA import A
>>
>> before the "class B" statement.
>
>Obviously no. Please note that A needs to know about B in this example
>(line: self.x = B() in the class A).
Ouch. I can think of several ways around this, but your current
question is too ambiguous to have any idea about the best way. What
you're doing is pretty ugly.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Project Vote Smart: http://www.vote-smart.org/
More information about the Python-list
mailing list