In the following program
1) I want to write the output to a file 2) And, also want to access the output file downstream in another process by piping the final output of the file, rather than reading from it.
With the following python code:
global product
product = ""
product_file = open('product.txt', 'w')
def read_file():
file1 = open ('file01.txt', 'r')
data1 = read.file1().rstrip('\n')
data1_lines = data1.split('\n)
for lines in data1_lines:
columns = lines.split('\t')
x = int(columns[0])
y = int(columns[1])
prod = x*y
output = open('product.txt', 'a')
output.write(str(x) + '\t' + str(y) + '\t' + str(prod))
output.close()
product += str(x +'\t'+ y +'\t'+ prod +'\n')
def manipulate_file():
global product;
for lines in product:
line = product.split('\t')
do..something.....
I want to access the final output file from def read_file()
to be used in the downstream process (function i.e def mainpulate_file()
) rather than opening it again.
I want to use either subprocess.call
and/or stdin-out
and/or tempfile
and finally clear the memory when done.
I read several examples but could not find anything clear to work out the process.
I would appreciate any explanation.