What is print? A function?
cam.ac.uk at mh391.invalid
Sun Jan 23 13:04:27 EST 2005
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.
That is not invoking it as a function. The parentheses are only for
ordering the expression on the right
You can do this too:
abc def ghi
> So I wonder, what _is_ exactly the print statement?
Uh, a statement.
> 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?
In the long run, you might want to look into the logging module. In the
print >>sys.stderr, text
debug = _debug_true
debug = _debug_false
That way you only have to check whether the option is true once in the
entire run of your program, not every time you call the debug() function
(which is presumably many times).
More information about the Python-list