[Tutor] Why super does not work !

Luke Paireepinart rabidpoobear at gmail.com
Mon Jan 17 23:37:23 CET 2011


I think it might be related to your multiple inheritance, maybe super is calling the init of observable on the listbox portion or something? I hardly ever do multiple inheritance so I'm not sure. What happens if you swap observable to be the first one?

-----------------------------
Sent from a mobile device. Apologies for brevity and top-posting.
-----------------------------

On Jan 17, 2011, at 3:47 PM, Karim <karim.liateni at free.fr> wrote:

> 
> 
> Hello,
> 
> I implemented Observer DP on a listbox (Tkinter) as follows and I don't understand why super() is not working and Observable.__init__(self) is working, cf below:
> 
> class ListObservable(Listbox, Observable):
>     """Creation de widget Listbox"""
>     def __init__(self):
>         super(ListObservable, self).__init__()
>         #Observable.__init__(self)
>         self._value = None 
>         self.listeContenu = StringVar()
>         self.listeContenu.set(' '.join(sorted(data_base.keys())))
>         self.liste = Listbox(listvariable=self.listeContenu,     selectmode='single')
>         self.liste.grid(row=0, column=1, sticky=N+S+W)
>         self.liste.bind('<Button-1>', self.onSelect)
> 
> The error is:
> Traceback (most recent call last):
>   File "./observerAppliGraphique.py", line 118, in <module>
>     app=App()
>   File "./observerAppliGraphique.py", line 37, in __init__
>     self.sujet.attach(self.nom)
>   File "/home/karim/guiObserver/observable.py", line 11, in attach
>     self._observers.append(observer)
> AttributeError: 'ListObservable' object has no attribute '_observers'
> 
> And the Observable class is:
> 
> class Observable(object):
>     """Sujet a observer"""
>     def __init__(self):
>         self._observers = []
>         print('constructeur observable')
> 
>     def attach(self, observer):
>         """Attache un nouvel observateur"""
>         self._observers.append(observer)
> 
>     def detach(self, observer):
>         """Retire un nouvel observateur"""
>         self._observers.remove(observer)
> 
>     def notify(self):
>         """Avertit tous les observateurs que l'observable change d'etat"""
>         for observer in self._observers:
>             observer.update()
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list