I built a code in python with multi classes and threads, after I start the code and because of While True loop, the Code keeps running and writing in each step a Report. I need to link an outside function to the running Code to print the report.
example:
Running code:
import threading ad TH
def WriteTXT()
file = open('File.TXT','a')
file.write('Test_WriteTXT')
file.close()
runLoop()
def runLoop():
th.start()
th = TH.thread(target = WriteTXT)
th.start()
Outside function:
def report():
file = open('File.TXT','w')
Txt_file = file.read()
print(Txt_file)
How to call report function and link it to the Running code to print Txt_file?
All you would do is call runLoop, WriteTxt, and report functions at the end of the code. You also have to import threading "as" TH instead of "ad", and missing a colon when defining the WriteTxt function. The new code might look like this below:
import threading as TH
def WriteTXT():
file = open('File.TXT','a')
file.write('Test_WriteTXT')
file.close()
runLoop()
def runLoop():
th.start()
def report():
file = open('File.TXT','w')
Txt_file = file.read()
print(Txt_file)
WriteTxt()
th = TH.thred(target = WriteTXT)
th.start()
runLoop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.