-1

I use a function call by API and provided by another party and no way to change it. for example, i use:

import api
...
api.login()
data=api.getData() #retry itself until success

The function will retry itself and print status every 1 sec until success, normally run at least 30 sec. I not want too many print out that I hard to troubleshoot. Is it possible to hidden printout under "getData()"?

singwong
  • 45
  • 11
  • Figure out what logging library they're using/logger and configure their logging to go to stderr. – Marcin Apr 01 '20 at 15:55
  • 1
    There are plenty of related questions, e.g. https://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr , https://stackoverflow.com/questions/2828953/silence-the-stdout-of-a-function-in-python-without-trashing-sys-stdout-and-resto – Demi-Lune Apr 01 '20 at 15:57
  • thank you. i dont really understand the relation of sys.stdout and print(). However, it works. – singwong Apr 01 '20 at 16:36

1 Answers1

0

i find the solution in Demi-Lune comments, thank you. it just add some code between the call function.

import sys
import api

...

api.login()

save_stdout = sys.stdout
sys.stdout = open('trash', 'w')
data=api.getData() #retry itself until success
sys.stdout = save_stdout
singwong
  • 45
  • 11