Re: EAFP gone wrong

2010-02-10 Thread Arnaud Delobelle
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, '

Re: EAFP gone wrong

2010-02-09 Thread Matthew Barnett
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

Re: EAFP gone wrong

2010-02-09 Thread Malte Helmert
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

Re: EAFP gone wrong

2010-02-09 Thread Malte Helmert
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()

Re: EAFP gone wrong

2010-02-09 Thread Ben Finney
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. […]

EAFP gone wrong

2010-02-09 Thread Arnaud Delobelle
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):