我在django代码中遇到了一个奇怪的情况,python拒绝接受两个字符串相等:
def depticon(depta):
print(f'depta is {depta}')
print(f'Testing |{depta}| against |Ear, Nose, Throat|')
if depta=="Ear, Nose, Throat":
icon = "ear.png"
print("Matched ENT")
else:
print("No match")
icon = "health-sign.png"
print(f'Icon is {icon}')
return icon
这就是它的名字。这里,诊所是一个查询集:
specialties = []
specialtytext = []
specialtyicon = []
for clinic in clinics:
if clinic.doctorid.dept not in specialties:
dept = clinic.doctorid.department
specialties.append(dept)
specialtytext.append(depttext(dept))
specialtyicon.append(depticon(dept))
查看输出:
depta is Ear, Nose, Throat
Testing |Ear, Nose, Throat| against |Ear, Nose, Throat|
No match
Icon is health-sign.png
我将|
字符放在字符串周围,以检查字符串中是否有任何特殊字符。你知道吗
我怀疑
depta
参数的类型不是str
,这就是为什么它不匹配str
值“Ear,Nose,though”。在进一步使用之前,请尝试将department
值传递给str()
。你知道吗有趣的事实:
print()
函数使用str()
自动转换参数。你知道吗相关问题 更多 >
编程相关推荐