python - How can I read the content of a file streamed with csv.writer? -
i have complex structure involves object (called mc class myclass in following simplified code) supposed to, on occasions, add lines csv file (test1.csv , test2.csv in example).
the program server need stay waiting in end. here replaced whole part pending input noticed same problem occurs in case.
here simplified program:
import csv class myclass(object): def __init__(self): csvfile = open("./test1.csv", 'w', encoding='utf-8', newline='') stream = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.quote_minimal) stream.writerow(["stream created"]) csvfile2 = open("./test2.csv", 'w', encoding='utf-8', newline='') self.stream2 = csv.writer(csvfile2, delimiter=',', quotechar='|', quoting=csv.quote_minimal) self.stream2.writerow(["stream2 created"]) def do(self): self.stream2.writerow(["done"]) mc = myclass() mc.do() _ = input("doing pause") so here create object "mc", creating @ same time 2 streams. stream1 gets closed when initialization over, 1 line being added, stream2 kept attribute later use.
if leave input pending can notice both test1.csv , test2.csv created, test1.csv has line expect , test2.csv empty (i expect have lines "stream2 created" , "done"). if make program finish test2.csv becomes filled needed.
my problem check contents of files without ending server , keep possibility write more of them. how can that?
Comments
Post a Comment