[Tutor] Why super does not work !

Izz ad-Din Ruhulessin izzaddin.ruhulessin at gmail.com
Mon Jan 17 22:53:08 CET 2011


It looks like because of something Observable doesn't have that attribute.
Could you post the ListBox class?

2011/1/17 Karim <karim.liateni at free.fr>

>
>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110117/bd7e020b/attachment.html>


More information about the Tutor mailing list