c macros in python.

ici iltchevi at gmail.com
Sun May 6 17:22:30 EDT 2007


On May 7, 12:01 am, noagbodjivic... at gmail.com wrote:
> 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(...)?
All in Python is pointer to object, and functions too, so

o = outfile.write
o("Some Text")

You can redirect print to file also:

print >> outfile, "Text", var1, var2[2:]
or
o = outfile
print >> o, "Text", var1, var2[2:]
:)





More information about the Python-list mailing list