try..except or type() or isinstance()?
Sibylle Koczian
nulla.epistola at web.de
Sat Aug 15 05:47:03 EDT 2020
Am 15.08.2020 um 10:14 schrieb Manfred Lotz:
> Hi Chris,
> Thanks a lot for you advice.
>
> On Sat, 15 Aug 2020 16:15:29 +1000
> Chris Angelico <rosuav at gmail.com> wrote:
>
>> On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz <ml_news at posteo.de>
>> wrote:
>>>
>>> I have an object which I could initialize providind an int or a str.
>>>
...
>
> For my use case I don't like this solution as I get the value which
> could be an int or str from a file. Means I would have to check the
> type beforehand in order to know if I have to do O4(val) or
> O4.from_name(val).
>
> Otherwise, it is admittedly a very good pattern.
>
>
Possibly silly question: if the value comes from a file, isn't it a
string in any case? A string that may be convertible to int or not? Or
what sort of file do I overlook?
Curious,
Sibylle
More information about the Python-list
mailing list