var 1 is constantly changing with every new line that is written in the csv file. Any suggestion how can I get the value outside of the function. This example does not work for me. I updated my code and added second function which is exactly the same but is reading another file. Now I only get print from the first function only. If I disable the first function I can get the print from the second function. Is there a way to print both of them or maybe three or four if I add later new functions ?
import sys
import time
import datetime
import os
class Application():
def loop_one(self):
filename = 'Test.csv'
mycsv = open(filename, 'r')
mycsv.seek(0, os.SEEK_END)
while 1:
time.sleep(1)
where = mycsv.tell()
line = mycsv.readline()
if not line:
mycsv.seek(where)
else:
arr_line = line.split(',')
var1 = arr_line[5]
mydate = datetime.datetime.now()
print var1, mydate.strftime("%H:%M:%S:%f")
return var1
def loop_two(self):
filename2 = 'Test2.csv'
mycsv2 = open(filename2, 'r')
mycsv2.seek(0, os.SEEK_END)
while 1:
time2.sleep(1)
where2 = mycsv2.tell()
line2 = mycsv2.readline()
if not line2:
mycsv2.seek(where2)
else:
arr_line2 = line2.split(',')
var2 = arr_line2[5]
mydate2 = datetime.datetime.now()
print var2, mydate.strftime("%H:%M:%S:%f")
return var2
s = Application()
var1 = s.loop_one()
var2 = s.loop_two()
var1 = s.loop_one()ifandelsestatement be within thewhileloop?