Adding print-style function calls, and preproc plugins

Gerson Kurz gerson.kurz at t-online.de
Thu Aug 30 01:23:41 EDT 2001


1) normally, you call functions in python like this:

name '(' arg { ',' arg } ')'

however, 'print' is a special function in that its arguments can be
written without enclosing brackets. Wouldn't it be nice if you *could*
call your "normal" functions in the same way? Would that require too
much of a change to the python language?

I came up on the idea during work with my now multithreaded webserver.
In singlethreaded mode, I redirected sys.stdout to the socket (or
rather, a cache to be written to that socket) and used print
statements to nicely generate webpages. Now, in multithreaded mode I
need a context for the output, so I have to call a function instead;
which meant that I had to not only replace "print" by "context.write",
but also enclose the arguments in brackets.

There might be a slight ambiguity when function names are used without
arguments, because it then could be interpreted as either the function
object or the function call; but then again, I see writing the
function name as object without assigning it to some variable or some
such as rather pointless. 

IIRC VB (yuk!) can do something similar. But then, VB is possibly the
*worst* kind of advocacy possible.

2) It would be nice if you could insert "preprocessor plugins" in the
python interpreter: python scripts, that preprocess the text before
interpreted. You can always add eval()/exec() statements to your code,
but it would be nice if they were to be added automatically. Then, a
syntax change like the one described in 1) could be easily added to
the interpreter for those who would like to have it. But, maybe thats
already possible and I only don't know of it ? 



More information about the Python-list mailing list