AttributeError into a bloc try-except AttributeError

Vincent Vande Vyvre vincent.vande.vyvre at telenet.be
Sun Jun 12 04:30:23 EDT 2016


Le 12/06/16 09:20, Vincent Vande Vyvre a écrit :
> Hi,
>
> I have a strange behaviour in my code.
>
> In an interactive session, the result is as expected:
>
> Python 3.4.3 (default, Oct 14 2015, 20:28:29)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> a = None
> >>> try:
> ...     _ = a.value
> ... except AttributeError:
> ...     print('OK')
> ...
> OK
> >>>
>
> But not in my code:
>
>     def call_settings_dialog(self):
>         try:
>             _ = self.video.category
>             self.core.artelive.configure_downloading(self.video)
>         except AttributeError:
>             self.core.artetv.configure_downloading(self.video)
>
> and ...
>
> Traceback (most recent call last):
>   File "/home/vincent/qarte-3/trunk/loadingscheduler.py", line 240, in 
> call_settings_dialog
>     _  = self.video.category
> AttributeError: 'TVItem' object has no attribute 'category'
>
> I have two types of video, one with an attribute category handled by a 
> module 'artelive' and an other without this attribute handled by an 
> other module, that's the reason of this code.


... I have just rewrite the line "_ = self.video.category" and the 
problem disappears.

Vincent


More information about the Python-list mailing list