sufficiently pythonic code for testing type of function
Theerasak Photha
hanumizzle at gmail.com
Wed Oct 11 02:09:57 EDT 2006
On 10/11/06, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> "Theerasak Photha" <hanumizzle at gmail.com> writes:
> Far better is to take the objects passed, *use* them in the way that
> you need to use them, and catch exceptions that get raised at the
> point where there is enough context to handle them. This is the
> "Easier to Ask Forgiveness than Permission" (EAFP) principle, and it
> is considered to be far more Pythonic.
Again, someone asked me to write the code for him in a personal
response to a previous thread. I simply executed his wishes (albeit
poorly).
I knew about EAFP before Python; in Ruby we have 'duck typing' and
there's a whole chapter about its virtues in Pick Axe. Myself I am a
strong proponent of this method, also known in OO Perl lingo, which I
know well, as interface polymorphism (Conway).
The main reason I *didn't* grok isinstance was b/c I never really
thought to use it before... :)
-- Theerasak
More information about the Python-list
mailing list