realtime output and csv files

lucan lucan at NNN.it
Fri Feb 5 14:49:32 EST 2016


I'm new of python adn I'm using it only to complete some experiments.
I'm reading a series of data from various sensors and in the meantime 
I'm writing datas on a file. I would like to print output in realtime 
(or refresh it when I need) but the problem is that I'm writing on a 
file every x seconds (my timestep).
Anyway from the moment that datas are scientific value is it correct to 
write on a file using str(temp) and separating with ","?
I need a csv file to read it with some data analysis softwares.


...
now = datetime.datetime.now()
dayexperiment = str(now.day)+str(now.month)+str(now.year)

myfilename ="myData"+dayexperiment+".dat"

index = 0
count = 1

timestep = 10


with open(myfilename,'w') as f:
f.write('#Index Time Value')
while True:
	reading = ...
     	...
	temp=...

         print 'Temp{0:0.3F}*C'.format(temp)

	now = datetime.datetime.now()
	file.write('\n'+str(index))
	
f.write(str(index)+','+str(now.hour)+':'+str(now.minute)+', '+str(temp))
		
		index +=1
		time.sleep(timestep)







More information about the Python-list mailing list