it should simple save results of program .txt file, when several strange things happen. first, while takes few seconds terminal print results, takes several minutes results write .txt file. also, when open text file, not save of information printed on shell! instead of full results, "54313806']" first line , last bit of results save text file underneath that. results displaying in terminal.
i checked other inquiries find out how save results in text file, have:
with open("output.txt", "w+") output: subprocess.call["python", "./my_program.py"], stdout=output) any idea on happening? or should try find different way save output text file?
here full code:
import re import subprocess f = open('my_program.py') raw = f.read() raw = raw.lower() l = raw.splitlines() l = [re.sub(r'\t', ' ', l) l in l] kiwis = [] elem in l: kiwis.append(elem.strip().split(' ')) kiwis in kiwis: data = kiwis[0:3] #extracting first 3 elements every line print data open("output.txt", "w+") output: subprocess.call["python", "./my_program.py"], stdout=output)
i don't think it's idea recursively calling program inside ... you're spawning infinite subprocesses. forget subprocess bit , write file this:
with open("output.txt", "w+") output: kiwis = [] elem in l: kiwis.append(elem.strip().split(' ')) kiwis in kiwis: data = kiwis[0:3] #extracting first 3 elements every line output.write(data)
Comments
Post a Comment