c macros in python.

Amaury Forgeot d'Arc afaNOSPAM at neuf.fr
Sun May 6 17:06:58 EDT 2007


noagbodjivictor at gmail.com a écrit :
> Hey,
> 
> I'm writing a script to generate code. I'm a bit tired of typing
> outfile.write(....). Does python have a way to c-like macros? Every
> instance of o(...) in the code will be replaced by outfile.write(...)?

First: Python has no macro facility.

But in this particular case, it is very simple. Just add:
    o = outfile.write
after the variable outfile is initialized.
It is not a macro (just another name for a function object)
but it looks the same...

-- 
Amaury



More information about the Python-list mailing list