Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Stef the Dutchman learning Python.  (Read 80289 times)

0 Members and 1 Guest are viewing this topic.

Stef

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Mac OS
    Stef the Dutchman learning Python.
    « 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

    Allan

    • Moderator

    • Mastermind
    • Thanked: 1260
    • Experience: Guru
    • OS: Windows 10
    Re: Stef the Dutchman learning Python.
    « Reply #1 on: June 07, 2021, 05:31:00 PM »
    Are you asking a question?

    Stef

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Mac OS
      Re: Stef the Dutchman learning Python.
      « Reply #2 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.

      Stef

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Mac OS
        Re: Stef the Dutchman learning Python.
        « Reply #3 on: June 12, 2021, 06:01:40 PM »
        It works