Luis P. Mendes a écrit :
> Hi,
> 
> I have the following problem:
> 
> I instantiate class Sistema from another class.  The result is the same
> if I import it to interactive shell.
> 
> s = Sistema("par")
> 
> class Sistema:
>     def __init__(self, par):
>         cruza_ema = CruzaEmas(par)
> 
> class CruzaEmas(Ema, Cotacoes):
>     def __init__(self, par):
>         Cotacoes.__init__(self, par)  <- calls ancestor class' __init__
> 
> class Cotacoes:
>     def __init__(self, par):
>         print "par: ", par
>         self.a()
>     def a(self):                      <- just as an example
>         print "ffffffffffffff"
 >
 > Method a() is not called.  Why is this?

Because there are far too many errors before ?

 > What is the best option to
 > solve this?

Fixing obvious errors would be a good start IMHO.

I tried to run your snippet. Here's a snapshot of the session:

[EMAIL PROTECTED] playground $ cat cotacoes.py
s = Sistema("par")

class Sistema:
     def __init__(self, par):
         cruza_ema = CruzaEmas(par)

class CruzaEmas(Ema, Cotacoes):
     def __init__(self, par):
         Cotacoes.__init__(self, par)  <- calls ancestor class' __init__

class Cotacoes:
     def __init__(self, par):
         print "par: ", par
         self.a()
     def a(self):                         <- just as an example
         print "ffffffffffffff"

[EMAIL PROTECTED] playground $ python cotacoes.py
   File "cotacoes.py", line 9
     Cotacoes.__init__(self, par)  <- calls ancestor class' __init__
                                                   ^
SyntaxError: invalid syntax
[EMAIL PROTECTED] playground $

(fix)

[EMAIL PROTECTED] playground $ python cotacoes.py
   File "cotacoes.py", line 15
     def a(self):                         <- just as an example
                     ^
SyntaxError: invalid syntax

(fix)

[EMAIL PROTECTED] playground $ python cotacoes.py
Traceback (most recent call last):
   File "cotacoes.py", line 1, in ?
     s = Sistema("par")
NameError: name 'Sistema' is not defined

(fix)

[EMAIL PROTECTED] playground $ python cotacoes.py
Traceback (most recent call last):
   File "cotacoes.py", line 5, in ?
     class CruzaEmas(Ema, Cotacoes):
NameError: name 'Ema' is not defined

(fix with a dummy class)

[EMAIL PROTECTED] playground $ python cotacoes.py
Traceback (most recent call last):
   File "cotacoes.py", line 8, in ?
     class CruzaEmas(Ema, Cotacoes):
NameError: name 'Cotacoes' is not defined

(grr... fix)

[EMAIL PROTECTED] playground $ python cotacoes.py
par:  par
ffffffffffffff

here's the fixed code:

[EMAIL PROTECTED] playground $ cat cotacoes.py
class Sistema:
     def __init__(self, par):
         cruza_ema = CruzaEmas(par)

class Ema:
     pass

class Cotacoes:
     def __init__(self, par):
         print "par: ", par
         self.a()
     def a(self):                         # <- just as an example
         print "ffffffffffffff"

class CruzaEmas(Ema, Cotacoes):
     def __init__(self, par):
         Cotacoes.__init__(self, par)  # <- calls ancestor class'

s = Sistema("par")
[EMAIL PROTECTED] playground $

It would have been nice to take the time to test your snippet at least 
once.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to