Python Forum
[split] Check presence of a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Check presence of a file
#1
Hi,
I have been trying to create something like this for a while to use with a flask app, I am trying to learn python3 so I am lost with the above, I want to create a module that I can import

 def read_sensor(sensorID)
   tempfile = open("/sys/bus/w1/devices/"+ sensorID +"/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    tempdata = thetext.split("\n") [1].split(" ")[9]
    temperature = float(tempdata[2:])
    temp = temperature / 1000
    print (temp"sensorname")


with a seperate file with a list of the sensors

# Execute DS18B20 function for sensor ID's below.
    solar_panel = float(read_ds18b20('28-0516a3ff90ff'))   
    top_cyl = float(read_ds18b20('28-0317003f1cff'))   
    flow_panel = float(read_ds18b20('28-0416c4a3a0ff'))   
(I have stolen the code from above) I want the name of the sensor to print out with its temperature. I know the code needs to be modified.
Can any one tell me if the first code will work as a module to be imported ie:
import readsensor as sensorID ??? and if then I would be able to call the function with:

read_sensor(solar_panel) ???
so that I can then use the returned value to compare with another to operate the solar pump ie:

while
solar_panel + 5 > flow_panel
GPIO.output(relay,GPIO.HIGH)
As you can see I have a lot to learn!!!
I am using a pi zero 4gb card stretch 9 lite via ssh
Any help greatly wanted
Paul
Reply


Messages In This Thread
[split] Check presence of a file - by pascale - Jun-22-2018, 10:34 PM
RE: [split] Check presence of a file - by pascale - Jun-23-2018, 08:34 PM
RE: [split] Check presence of a file - by pascale - Jun-23-2018, 09:10 PM
RE: [split] Check presence of a file - by pascale - Jun-23-2018, 09:32 PM
RE: [split] Check presence of a file - by pascale - Jun-24-2018, 09:28 AM
RE: [split] Check presence of a file - by pascale - Jun-24-2018, 10:33 AM
RE: [split] Check presence of a file - by snippsat - Jun-24-2018, 11:01 AM
RE: [split] Check presence of a file - by pascale - Jun-24-2018, 12:17 PM
RE: [split] Check presence of a file - by pascale - Jun-24-2018, 05:29 PM
RE: [split] Check presence of a file - by pascale - Jun-24-2018, 07:03 PM
RE: [split] Check presence of a file - by pascale - Jun-24-2018, 08:59 PM
RE: [split] Check presence of a file - by pascale - Jun-25-2018, 06:54 AM
RE: [split] Check presence of a file - by pascale - Jun-25-2018, 12:56 PM
RE: [split] Check presence of a file - by pascale - Jun-27-2018, 08:33 PM
RE: [split] Check presence of a file - by pascale - Jun-29-2018, 09:41 AM
RE: [split] Check presence of a file - by pascale - Jul-08-2018, 12:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to "tee" (=split) output to screen and into file? pstein 6 1,398 Jun-24-2023, 08:00 AM
Last Post: Gribouillis
  Split pdf in pypdf based upon file regex standenman 1 2,096 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  please check this i wanna use a csv file as a graph xCj11 5 1,499 Aug-25-2022, 08:19 PM
Last Post: deanhystad
  check if a file exist on the internet and get the size kucingkembar 6 1,769 Apr-16-2022, 05:09 PM
Last Post: kucingkembar
  How to split file by same values from column from imported CSV file? Paqqno 5 2,799 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  [split] Results of this program in an excel file eisamabodian 1 1,580 Feb-11-2022, 03:18 PM
Last Post: snippsat
  Code to check folder and sub folders for new file and alert fioranosnake 2 1,947 Jan-06-2022, 05:03 PM
Last Post: deanhystad
  split txt file data on the first column value shantanu97 2 2,444 Dec-29-2021, 05:03 PM
Last Post: DeaD_EyE
  [split] Help- converting file with pyton script eltomassito 6 3,254 Jul-02-2021, 05:29 PM
Last Post: snippsat
  Check last time file was accessed Pavel_47 4 2,842 Jun-01-2021, 05:47 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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