I'm trying to implement a basic debugging flag into my code. I'm planning on doing this by binding print to logFile.write so instead of logging the process my code executes, it'll print it so the user can see it done and see where it may mess up. I do the same technique by binding raw_input to input for backwards compatibility for python 2 and python 3, but when I try binding print to anything, I get a Syntax Error.
On Python 3 on Windows the line runs correctly, but when run on python 2 on UNIX or Windows it fails.
# If user has passed the 'debug' parameter then no log file will be created and instead will be printed in terminal
if (len(sys.argv) > 1 and sys.argv[1] == 'debug') or (len(sys.argv) > 2 and (sys.argv[1] == 'debug' or sys.argv[2] == 'debug')):
try:
logFile.write = print
except:
print('Debug is not working at this time')
This is the error I receive
SyntaxError: invalid syntax
lax94t01> ./Automation.py userconfig.ini debug
File "./Automation.py", line 55
logFile.write = print
^