Python Macros

Jeff Shannon jeff at
Wed Oct 6 02:34:13 CEST 2004

Arich Chanachai wrote:

> Jeff Shannon wrote:
>> (This sort of setup, with the caller taking responsibility for 
>> failure rather than the callee attempting to make sure that *someone* 
>> handles failure, is far more common in Python than the sort of scheme 
>> that you're asking for.)
> Right, I want the callee to handle it, no responsibility for the caller.

Given what you posted, it looked to me as if you had seen/used this 
particular feature in other languages, and therefore expected/wanted it 
in Python.  My point was that, while it may be a standard idiom 
elsewhere, it is probably *not* the best way to do things in Python.  
There may be cases where it *is* actually desirable (I've never found it 
necessary, but then I can't claim a tremendous amount of experience 
either), but you should be aware that it's not the *normal* way of doing 
things even if you then choose to go ahead with it.

Often, someone wants to use a particular syntax feature out of 
familiarity, rather than because it's really the best fit for the job at 
hand.  This is particularly true when coming to a new language; one 
naturally wants to continue programming in the style of the language(s) 
one already knows, but that style may be completely inappropriate for 
the new language.  Others have shown you how to force Python into the 
style that you're used to; I'm suggesting alternative styles that will 
fit better with the way that Python normally works.  It's almost always 
better to use Python idioms when coding in Python, Scheme idioms when 
coding in Scheme, and Java idioms when coding in Java, than it is to try 
to write Python using Scheme idioms.

Feel free to push responsibility onto the callee if you really think 
that's the best way to handle your particular scenario.  I'm just trying 
to make you aware that it's not the way that most experienced Python 
programmer would be likely to do it, and that you might benefit by 
considering the sort of solution that an experienced Python programmer 
would use even if it's different from your initial inclinations.

Jeff Shannon
Credit International

More information about the Python-list mailing list