Python Forum
"." to "," when writing to .txt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"." to "," when writing to .txt
#1
import time
from datetime import datetime

DS18B20="/sys/bus/w1/devices/28-01204febab44/w1_slave"

while True:
   
   now = datetime.now()
   dt_string = now.strftime('%d/%m/%Y   %H:%M:%S ')
   
   f = open(DS18B20, "r")
   data = f.read()
   f.close()
   (discard, sep, reading) = data.partition(" t=")
   t = float(reading) / 1000.0
   
   print dt_string, '{:.1f}*C' .format(t)
   time.sleep(4) 

   f = open("data.txt", "a+")
   print >> f, dt_string, '{:.1f}*C%' .format(t)
Google - non
Dutch forums - non
US general forums - non
General tutorials and etc. - non (Yes, without my own code and in basic it works)
Time spend with experimenting, maybe over 10.00 hours.

Goal: Change my output print >> f with replace "." tot "," while writing to .txt.
It's my first time writing code and spent a lot of time and now I'm stuck at this last peace. I need to tackle this problem before I can go further in my project with writing more code for a lot of different sensors. The only thing I can think of now is making a second .txt en reed out the first data.txt to change the . to , only I think that that is not the perfect solution and is somehow not logic to me.

Asking: Can somebody tell me if it is possible and if it is, give me some hints how to figure this out. If it is not possible than it would be ridicules to spend many hours extra. It is just agonizing me that I can't figure this out....

With kind regards,
Lullaby (Dutchman).
Reply


Messages In This Thread
"." to "," when writing to .txt - by Lullaby - Jun-11-2021, 11:34 PM
RE: "." to "," when writing to .txt - by Lullaby - Jun-12-2021, 08:22 PM
RE: "." to "," when writing to .txt - by Lullaby - Jun-12-2021, 09:45 PM
RE: "." to "," when writing to .txt - by bowlofred - Jun-12-2021, 09:59 PM
RE: "." to "," when writing to .txt - by Lullaby - Jun-12-2021, 10:47 PM
RE: "." to "," when writing to .txt - by Lullaby - Jun-12-2021, 10:59 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020