Jun-07-2020, 05:11 AM
(This post was last modified: Jun-07-2020, 05:11 AM by Gribouillis.)
You can add a file handle argument to
The drawback of this code is that the GUI will freeze during the call to clr_fn_no_print_outut(). To avoid this, you can use the technique with the after() method as I said in your other thread about this subject.
clr_yes_fn_no_print_output()
def clr_fn_no_print_output(host, file=sys.stdout): ... for line in p.stdout: print(line, end=' ', file=file)Then in the code that calls this function you give a StringIO instance as file argument
import io ofh = io.StringIO() clr_fn_no_print_output(host, file=ofh) self.text_window.insert(tk.END, ofh.getvalue())It's an example of dependency injection. As far as I know, functions that do input output operations are good candidates for dependency injection.
The drawback of this code is that the GUI will freeze during the call to clr_fn_no_print_outut(). To avoid this, you can use the technique with the after() method as I said in your other thread about this subject.