polymorphism w/out signatures?
Peter Hansen
peter at engcorp.com
Mon May 10 13:19:08 EDT 2004
Robin Munn wrote:
> Simon Brunning <simon at brunningonline.net> wrote:
>
>>def setText(window, text, append=False):
>> # Ensure that text is a list
>> try:
>> text + ''
>> text = [text]
>> except TypeError:
>> pass
>>
>> ... rest of funtion, which can assume that 'text' is a list
>
>
> That would be better with an "else:" clause:
>
> try:
> text + ''
> except TypeError:
> pass
> else:
> test = [text]
Just to verify, you think it's better solely because
of the improved readability, right?
Or is there some way that the following code can
possibly fail with a TypeError, for any reason
whatsoever?
someName = [someName]
-Peter
More information about the Python-list
mailing list