The main reason would be to see if it's possible and explore how best
to do it. You mention C#, C++, and Java, none of which have decent
macro systems. I'd encourage you to look at Lisp and Scheme for some
of the things they're able to do with macros.
The actual use cases that motivated me to actually start were:
* The collections.namedtuple class factory in the Python 2.6 standard
library. This uses a large triple-quoted string that is then exec'd
in order to produce a new class. Building code via string
manipulation is, in my opinion, even *more* insane than using macros.
In fact, the MetaPython tutorial is all based around showing how you
can write collections.namedtuple more succinctly using macros.
* Sometimes, you need to strip logging out of performance-critical
code. It's not enough to just set the log level because you still
incur the overhead of a function call and the overhead of evaluating
all the arguments to the logger function.
If you want more information, you can look at my blog at
http://blog.pythonisito.com,
particularly the post
http://blog.pythonisito.com/2009/03/python-macros.html
where I ask for input from anyone who reads my blog. There's also a
question I posted on StackOverflow asking for use cases:
http://stackoverflow.com/questions/764412/python-macros-use-cases .
In general, any time you find yourself writing a big string and then
exec-ing it, you might use a macro instead. If you never do this, you
probably don't need macros, anyway.
-Rick