realtime output and csv files

Joel Goldstick joel.goldstick at gmail.com
Fri Feb 5 16:43:15 EST 2016


On Fri, Feb 5, 2016 at 4:13 PM, Bernardo Sulzbach <mafagafogigante at gmail.com
> wrote:

> On 02/05/2016 07:09 PM, lucan wrote:
>
>>
>> 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))
>>
>
You might want to do this:

f.write("%d, %2d:%2d, %.1f" % (index, now.hour, now.minute, temp))

In my test:

>>> print("%d, %2d:%2d, %.1f" % (1,10,24,20.4))
1, 10:24, 20.4

This uses the original python formatting method.  There is a newer one as
well

>
>> Or if there is a better way to do that.
>>
>>
> If you got your newlines and headers (if the other program requires it)
> right, this should be all you need.
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays


More information about the Python-list mailing list