0

I have overloaded the built in print function in python to send data over a socket whenever my script prints anything.Now, I am running another python script through the main script using execFile -> execfile(os.path.join(mainFileDirectory, mainFileNamesList[i])). Inside this execFile call,the script which is being loaded no more uses the custom print function I have overloaded in the main script. How can I change the scope of the overridden print function.Thanks.

  • 1
    What you probably want to do is not override the `print` function, but change `sys.stdout` to a class that sends the data over the socket. – kindall May 25 '17 at 15:56
  • Write Modules with functions, that gets some output-function directly. Don't use `execFile`. – Daniel May 25 '17 at 16:02
  • @kindall As I use this link as an example to change the sys.stdout (https://stackoverflow.com/questions/14986490/python-change-sys-stdout-print-to-custom-print-function) , I am getting a new error which says ; AttributeError: writer instance has no attribute 'writers' – user3731645 May 26 '17 at 06:52

0 Answers0