You could override print as per DevPlayer's post here on StackOverflow, slightly modified here:
from __future__ import print_function
# Note: If you are using Python 3 leave this line out
# This must be the first statement before other statements.
# You may only put a quoted or triple quoted string,
# Python comments or blank lines before the __future__ line.
import sys
def print(*args, **kwargs):
"""My custom print() function."""
# Adding new arguments to the print function signature
# is probably a bad idea.
# Instead consider testing if custom argument keywords
# are present in kwargs
sys.stdout.write('hello')
return __builtins__.print(*args, **kwargs)
print ("hello there")
print (" hi again")
[Edit] ...or as DSM suggests, you could avoid the sys call with this:
from __future__ import print_function
# Note: If you are using Python 3 leave this line out
# This must be the first statement before other statements.
# You may only put a quoted or triple quoted string,
# Python comments or blank lines before the __future__ line.
def print(*args, **kwargs):
"""My custom print() function."""
# Adding new arguments to the print function signature
# is probably a bad idea.
# Instead consider testing if custom argument keywords
# are present in kwargs
__builtins__.print('hello',end='')
return __builtins__.print(*args, **kwargs)
print ("hello there")
print (" hi again")