The short script below is a part of a Nikon camera control script on my rasberry PI 4 to control long exposures of my Nikon D90. I call a command that tests if the camera is communicating, the result is in variable mycmd. The script below I just create the string. But my if statement always fails to find a match on less Nikon is the only word in mycmd.
import os
import time
import subprocess
import sh
mycmd =("Nikon DSC D90 (PTP mode) usb:001,008")
if mycmd == ('Nikon'):
print('gotit')
#mycmd = os.popen('gphoto2 --auto-detect').read()
print(mycmd)
time.sleep(1)
#print(encoded_bytes)
#decoded_string = encoded_bytes.decode('utf-8','replace')
#print(decoded_string)
if mycmd == ('Nikon'):
print("OK")
else:
print("error")`
The OUTPUT Below
>> %Run os.popen_example.py
Nikon DSC D90 (PTP Mode) usb:001,008
error
>>