I would like a copy of the print
function that is called debug
. How can I alias a function in Python?
You can simply assign debug = print
in Python 3.
In Python 2 print
isn't a function. There no way to give yourself a debug
statement that works exactly like print
(print 1,
, print 1 >> sys.stderr
etc.). Best you can do is write a wrapper around the print
statement:
def debug(s): print s
You can also disable the print
statement and use the Python 3 version:
from __future__ import print_function debug = print
If you do this, you cannot use the statement version (print x
) anymore. It's probably the way to go if you're not breaking any old code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With