No macros in Python

Carl Banks imbosol at vt.edu
Sun Dec 15 20:37:47 EST 2002


Lulu of the Lotus-Eaters wrote:
> But in general I would challenge
> Cherniavsky, or anyone else, to present a case where anything could be
> done significantly more easily in Python if macros were added.  I really
> do not think there are any such situations.

Here is the macro I've most often wished I had (in other languages,
not Python):

defmacro call_but_return_if_false(function,*args,**kwargs):
    result = function(*args,**kwargs)
    if not result:
        return

The return statement would return from the function this macro is
expanded in, of course.  I don't need it in Python because exceptions
are a much better method here.  God knows the Python source code could
use it.


-- 
CARL BANKS



More information about the Python-list mailing list