On May 7, 7:01 am, [EMAIL PROTECTED] 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(...)?
Functions and methods are first-class citizens in Python; all you have to do is: o = outfile.write o('blah blah\n') o('etc\n') Bonus: your code will run (measurably but almost imperceptibly) faster, because you save a method lookup every time you use it.This would not happen with a text-substituting macro approach. HTH, John -- http://mail.python.org/mailman/listinfo/python-list