Python Forum
string with integer variable within
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string with integer variable within
#7
(Mar-12-2018, 01:41 AM)Larz60+ Wrote: please show your code, use BBCODE tags

#!/usr/bin/python
# Example using a character LCD connected to a Raspberry Pi or BeagleBone Black.
import time

import Adafruit_CharLCD as LCD


# Raspberry Pi pin configuration:
lcd_rs        = 25  # Note this might need to be changed to 21 for older revision Pi's.
lcd_en        = 24
lcd_d4        = 8
lcd_d5        = 7
lcd_d6        = 12
lcd_d7        = 16
lcd_backlight = 2

outdoor="/sys/bus/w1/devices/28-0517b184cdff/w1_slave"
indoor="/sys/bus/w1/devices/28-0517b196efff/w1_slave"


# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows    = 2

# Alternatively specify a 20x4 LCD.
# lcd_columns = 20
# lcd_rows    = 4

# Initialize the LCD using the pins above.
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
                           lcd_columns, lcd_rows, lcd_backlight)
while True:

    with open(outdoor) as odt:
        odt_contents = odt.read()
        odt_temp = odt_contents[69:75]
        temp_outdoor = int(float(odt_temp))
        outdoortemp = temp_outdoor / 1000 * 9 / 5 + 32
        
    with open(indoor) as idt:
        idt_contents = idt.read()
        idt_temp = idt_contents[69:75]
        temp_indoor = int(float(idt_temp))
        indoortemp = temp_indoor / 1000 * 9 / 5 + 32
        

    
    # Print a two line message
    lcd.clear()
    lcd.message("")

    # Wait 5 seconds
    time.sleep(5.0)
Where lcd.message("") is I would like it to print:

Indoor: (indoortemp)
and one line 2
Outdoor: (outdoortemp)

Basically print text and then the variable.
Reply


Messages In This Thread
string with integer variable within - by Andy1845c - Mar-11-2018, 10:05 PM
RE: string with integer variable within - by Andy1845c - Mar-12-2018, 02:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing String Variable with a new String Name kevv11 2 839 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 2,183 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 2,978 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 1,010 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 6,434 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 1,872 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  Split string using variable found in a list japo85 2 1,361 Jul-11-2022, 08:52 AM
Last Post: japo85
  Can you print a string variable to printer hammer 2 2,017 Apr-30-2022, 11:48 PM
Last Post: hammer
Question How to convert string to variable? chatguy 5 2,571 Apr-12-2022, 08:31 PM
Last Post: buran
  Question about change hex string to integer sting in the list (python 2.7) lzfneu 1 2,586 May-24-2021, 08:48 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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