Malte Helmert writes:
> Arnaud Delobelle wrote:
>
>> This means that EAFP made me hide a typo which would have been obviously
>> detected had I LBYLed, i.e. instead of
>>
>> try:
>> return val.latex()
>> except AttributeError:
>> ...
>>
>> do
>>
>> if hasattr(val, '
Arnaud Delobelle wrote:
Hi all,
Hi have a set of classes that represent mathematical objects which can
be represented as a string using a 'latex' method (after Knuth's famous
typesetting system). As I want to be able to typeset some builtin types as
well, I have a generic function, latex(), as
Ben Finney wrote:
> def latex(val):
> def make_result_in_the_absence_of_a_latex_method():
> result = transmogrify(val)
> return result
>
> try:
> typeset_func = val.latex
> except AttributeError:
> typeset_func = make_result_in_the_absence_of_a_latex_met
Arnaud Delobelle wrote:
> This means that EAFP made me hide a typo which would have been obviously
> detected had I LBYLed, i.e. instead of
>
> try:
> return val.latex()
> except AttributeError:
> ...
>
> do
>
> if hasattr(val, 'latex'):
> return val.latex()
Arnaud Delobelle writes:
> As I want to be able to typeset some builtin types as well, I have a
> generic function, latex(), as follows:
>
> def latex(val):
> try:
> return val.latex()
> except AttributeError:
[…]
> It's EAFP and I have used this for a while with no problem.
[…]
Hi all,
Hi have a set of classes that represent mathematical objects which can
be represented as a string using a 'latex' method (after Knuth's famous
typesetting system). As I want to be able to typeset some builtin types as
well, I have a generic function, latex(), as follows:
def latex(val):