Computer Hope

Software => Computer programming => Topic started by: Stef on June 07, 2021, 03:31:26 PM

Title: Stef the Dutchman learning Python.
Post by: Stef on June 07, 2021, 03:31:26 PM
Hello kind people,

At first, i'm Dutch and have some - a lot - problems writing in Englisch, so do appologise me for gramattica spelling en etc. You're language is realy differend from mine, and it will take some time for me to mengle in you're style of conversation (big difefrence in expressions en etc). Well thats that and i will overgome that problem by learning.

I will use this topic for learning and for help when needed, only i dont want the answers given on a sheet. See me like a student and homework what i got (age 39  ::))

My first piece of codeding (with some help and hours of testing) is:

Code: [Select]
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 ')
   
   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)
 

I'm building my own weather station with a RPi 3B and python code. Never dit something before and have no experiance in coding, so i'm testing and wrecking everything to see what happens. I'm using Geany for programming (thats fine for me now). I hope that this gives a small expression of what i am doing.

Thanks to Veltes and Quantos for the first introduction with my project.


Greetsss
Stef
Title: Re: Stef the Dutchman learning Python.
Post by: Allan on June 07, 2021, 05:31:00 PM
Are you asking a question?
Title: Re: Stef the Dutchman learning Python.
Post by: Stef on June 08, 2021, 04:01:30 AM
Yes, i have different questions but don't wanne spil them all over the place on the forum. And before anybody tels me the exact anwser i wanny try as mucht as possble so i can learn why things work or not.

At this moment i'm trying to figgure out how to change my "." in to "," for writing in the .txt. I found something like * Only i have not figgured out where to place it/use it


Code: [Select]
x = replace (".", ",")

Also in my prevorius post there is a line that tells the reading off my sensor. I dont understand why or how {:.1f} i dont have some refference where the 1f come's from...




I would appriciate some hints zo i can figgure this out.
Title: Re: Stef the Dutchman learning Python.
Post by: Stef on June 12, 2021, 06:01:40 PM
It works