Reply To: I need to get a True or False if a variable contains a string match

Welcome to Python Land Forums The Python Tutorial I need to get a True or False if a variable contains a string match Reply To: I need to get a True or False if a variable contains a string match

#2320
lostbit
Participant

I applied the if command to the real script and it does not work.

When check_camera has a groping of words including D90 it is not found.

I tried split I tried find with errors find not defined or missing attribute!!

I created a small script with check_camera = to the full string and again

check_camera = to just D90.

Here is the output

import time
import os
import sh
import sys

# below I just populate check_camera with the string coppied from
# shell terminal on my rasberry PI. The output print check_camera
# prints the same string. but if does not work.

print(“checking_camera”)
check_camera = (“Nikon DSC D90 (PTP mode) usb:001,005”)
print(check_camera)
if check_camera == (“D90”):
print(“found_camera”)
else:
print(“oops”)

#now check_camera only contains D90
print(“checking_camera”)
check_camera = (“D90”)
print(check_camera)
if check_camera == (“D90”):
print(“OK”)
else:
print(“shucks”)

import time
import os
import sh
import sys

# below I just populate check_camera with the string coppied from
# shell terminal on my rasberry PI. The output print check_camera
# prints the same string. but if does not work.

print(“checking_camera”)
check_camera = (“Nikon DSC D90 (PTP mode) usb:001,005”)
print(check_camera)
if check_camera == (“D90”):
print(“found_camera”)
else:
print(“oops”)

#now check_camera only contains D90
print(“checking_camera”)
check_camera = (“D90”)
print(check_camera)
if check_camera == (“D90”):
print(“OK”)
else:
print(“shucks”)

 

import time
import os
import sh
import sys

# below I just populate check_camera with the string coppied from
# shell terminal on my rasberry PI. The output print check_camera
# prints the same string. but if does not work.

print(“checking_camera”)
check_camera = (“Nikon DSC D90 (PTP mode) usb:001,005”)
print(check_camera)
if check_camera == (“D90”):
print(“found_camera”)
else:
print(“oops”)

#now check_camera only contains D90
print(“checking_camera”)
check_camera = (“D90”)
print(check_camera)
if check_camera == (“D90”):
print(“OK”)
else:
print(“shucks”)