Reputation: 909
Is there a single point where I can replace the print function newline char with a different one that will persist for the life of a program?
I am aware you can pass an end
char to print but this becomes a hassle to do for every single call.
The program interfaces with a legacy system and can be called from both a terminal emulator or through the website. This is how I am currently handling it.
if(web):
linebr='<br/>'
else:
linebr='/n'
# export linebr
... # elsewhere
print(what,end=linebr)
Is there a better way?
Upvotes: 1
Views: 46
Reputation: 4382
Define a new function that works as a customization of Python print()
function. For example:
def print_(s):
print(s, end="<br>")
Upvotes: 1