与Python中PyBluez的怪异字符串比较

问题描述 投票:0回答:1

我目前正在通过一些简单的代码尝试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.
python string string-comparison pybluez
1个回答
0
投票

不完全相同:

++++DESKTOP-XXXXXXX++++
++++Bob’s iPhone++++
Device Bob's iPhone not found.

或更好:

enlarged

[一个是笔直的'一个是弯曲的-因此:不相同。

使用

target_name = "Bob’s iPhone"   # curved one
© www.soinside.com 2019 - 2024. All rights reserved.