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:
>>> print("abc"),("def"),("ghi")
abc def ghiSo 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 short run:
def _debug_true(text):
print >>sys.stderr, textdef _debug_false(text):
passif command_line_debug_option:
debug = _debug_true
else
debug = _debug_falseThat 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).
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list
