Adding print-style function calls, and preproc plugins

Richard Jones richard at bizarsoftware.com.au
Thu Aug 30 02:40:14 EDT 2001


On Thursday 30 August 2001 15:23, Gerson Kurz wrote:
> 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.

No - unlike Perl (and other languages?), print in Python is not a function, 
it's a _statement_. See http://www.python.org/doc/current/ref/print.html

Simplest way of demonstrating this that I can think of:

>>> import sys
>>> sys.stdout.write
<built-in method write of file object at 0x80ec998>
>>> print

>>> sys.stdout.write('hello\n',)
hello
>>> print('hello\n',)
('hello\n',)


> 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?

Your proposal, which smells a lot of Perl, is actually one of my personal 
Seven Deadly Sins of Perl (modelled on the list found at 
http://language.perl.com/versus/perl.html, but lost forever when I stopped 
givinga damn about perl - right about when I got a full-time job working with 
python :)

In short, there's just too much possible ambiguity about the meaning of 
brackets. I mean come on, we got rid of the braces and (most of) the 
semicolons for you :)


> 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.

So, what's the call:

   def foo():
      return 1
   a = foo

Does that assign a to the function object, as it does at the moment, or does 
it assign a to 1?



    Richard




More information about the Python-list mailing list