What is print? A function?
segphault at sbcglobal.net
Mon Jan 24 11:02:22 EST 2005
On Sun, 23 Jan 2005 18:01:50 +0000, Frans Englich wrote:
> Nah, I don't think it's a function, but rather a builtin "statement". But
> it's possible to invoke it as an function; print( "test" ) works fine.
> So I wonder, what _is_ exactly the print statement? The untraditional
> way of invoking it(without paranteses) makes me wonder.
> The reason I thinks about this is I need to implement a debug print for
> my program; very simple, a function/print statement that conditionally
> prints its message whether a bool is true. Not overly complex.
> I tried this by overshadowing the print keyword, but that obviously
> didn't work.. Is defining a two-liner function the right way to go, or
> is there better ways to approach it?
Unfortunately, it isnt possible to add new kinds of statements to python.
you might want to have a look at Ruby, in which paren are entirely
optional. Ruby is similar to python in a lot of ways, but its also quite
different. It provides lots of syntactic sugar and a superior object
model, but its a resource hog compared to python.
You may also be interested in Logix. Logix is a language framework built
on top of python that allows you to dynamically extend python syntax at
run-time. Unfortunately, Logix is still rather new, and its incredibly
More information about the Python-list