我目前正在通过一些简单的代码尝试PyBluez。但是我遇到了这个非常基本的字符串比较问题。
import Bluetooth
target_name = "Bob's iPhone"
target_addr = None
nearby_devices = bluetooth.discover_devices(lookup_names = True)
for addr, name in nearby_devices:
print("++++" + str(name) + "++++")
if str(name) == target_name:
# Never reach here! Bob's iPhone is found, both 'str' type
target_addr = addr
if target_addr is not None:
print("Device {} is found with address: {}".format(target_name, target_addr))
else:
print("Device {} not found.".format(target_name))
.......
输出:
++++DESKTOP-XXXXXXX++++
++++Bob’s iPhone++++
Device Bob's iPhone not found.