Not sure how I would accomplish overriding the print('something') function do do something else in the class I am in.
For example, I have the following code:
import app
from app.helper import ws_send
class TemplateSubJob:
def __init__(self, sessiondata, sid, payload):
self.session = sessiondata
self.sid = sid
self.payload = payload
def startme(self):
ws_send(self.sid, self.payload, 'Send some output to the user...')
ws_send(self.sid, self.payload, 'Send something else to the user...')
print('test')
return b'xlsx_bytes_output'
I want to override the function print('something') to take what is passed and do something with it.
In my case I want to create a print function that does what ws_send() is doing, except only take a string.
Something like the following:
def print(string):
ws_send(self.sid, self.payload, string)
print('now i am being sent through ws_send instead of stdout')
How can I accomplish this?
UPDATE:
The reasoning for this is so anyone who is adding code to mine, does not need to modify their code or script to use my functions. I can hijack the print function that they are already using.