realtime output and csv files

2016-02-05 Thread lucan

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)





--
https://mail.python.org/mailman/listinfo/python-list


Re: realtime output and csv files

2016-02-05 Thread lucan



What do you mean? What is "datas"? What do you mean by "correct"?


"datas" I mean the values for example temperature = 20.4 (so they are 
floating point)


Index time temp
1 10:24 20.4
2 10:25 20.6
...

I wonder if this is correct "my way" to write a csv file:

file.write('\n'+str(index)) 
f.write(str(index)+','+str(now.hour)+':'+str(now.minute)+','+str(temp))


Or if there is a better way to do that.


CSVs is essentially text separated by commas, so you likely do not need
any library to write it "Just separating with ','" should work if you
are formatting them correctly.


ok.

--
https://mail.python.org/mailman/listinfo/python-list


Re: realtime output and csv files

2016-02-06 Thread lucan



I wouldn't be surprised if a parser treated a value as text only because
it has spaces on it.

For OP, if you are going for this, I - personally - suggest sticking to
"%d,%2d:%2d,%.1f".


you're rightin fact importing datas in spreadsheet I've had some 
problems. I'll follow this suggestion. tnks a lot! :)

--
https://mail.python.org/mailman/listinfo/python-list