Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if statement string match
#1
making a simple remote radio control program. radio listens for packets
and if none received, keep listening. Im needing it to check if transmitted strings
(onset and unset as custom string triggers) match as my "commands" to control
electrical relay on or off... and if they dont match my 2 commands (else) just decode
string as ascii text and print the text. cannot get it to recognize my elif lines...

while True:
    packet = rfm9x.receive()
    
    if packet is None:
        led.value = False
        print("Received nothing! Listening again...")
    elif packet is onset:
        print("its now on") 
    elif packet is unset:
        print("its now off") 
    else:
        led.value = True
        print("Received (raw bytes): {0}".format(packet))
        packet_text = str(packet, "ascii")
buran write Sep-04-2021, 04:50 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
if statement string match - by javiopro - Sep-04-2021, 04:37 PM
RE: if statement string match - by deanhystad - Sep-04-2021, 05:39 PM
RE: if statement string match - by javiopro - Sep-04-2021, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to compare string values in an if statement israelsattleen 1 583 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  String concatenation in SQL update statement hammer 3 1,571 Feb-24-2022, 08:00 PM
Last Post: hammer
  string match Kristenl2784 1 1,466 Jul-28-2020, 03:14 PM
Last Post: Kristenl2784
  regex match in a string batchen 4 3,259 Jan-20-2020, 08:48 AM
Last Post: batchen
  SyntaxError: EOL while scanning string literal on with open() statement Regulus 3 7,394 Feb-23-2018, 06:40 PM
Last Post: nilamo
  How to do String match SriRajesh 2 3,651 Apr-02-2017, 01:31 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

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