[英]Python - help() command - same string different results
I'm using the python help command with the same string but it's giving different results. 我正在使用具有相同字符串的python help命令,但它给出了不同的结果。
The code: 编码:
from BeautifulSoup import BeautifulSoup
link = BeautifulSoup("bilateralFilter")
title = link.getText()
string = "cv2." + title + ""
string2 = "cv2.bilateralFilter"
if string == string2:
print "----- Output 1 -------------"
print(type(string))
help(string)
print "----- Output 2 -------------"
print(type(string2))
help(string2)
Console output: 控制台输出:
----- Output 1 -------------
<type 'unicode'>
Help on unicode object:
class unicode(basestring)
| unicode(object='') -> unicode object
| unicode(string[, encoding[, errors]]) -> unicode object
...
----- Output 2 -------------
<type 'str'>
Help on built-in function bilateralFilter in cv2:
cv2.bilateralFilter = bilateralFilter(...)
bilateralFilter(src, d, sigmaColor, sigmaSpace[, dst[, borderType]]) -> dst
So if it is the same string the help shouldn't be returning the same? 所以如果它是相同的字符串,那么帮助不应该返回相同的字符串?
title
is a unicode
object. title
是一个unicode
对象。 "cv2." + title + ""
因此"cv2." + title + ""
"cv2." + title + ""
is also a unicode object. "cv2." + title + ""
也是一个unicode对象。 help
apparently only accepts non-unicode str
s for looking up names, such as string2
. help
显然只接受非unicode str
来查找名称,例如string2
。 string
and string2
are in fact different types, but str
and unicode
can still compare equal. 所以string
和string2
实际上是不同的类型,但str
和unicode
仍然可以比较相等。 title = u'bilateralFilter'
or string = u"cv2.bilateralFilter"
. 您可以使用title = u'bilateralFilter'
或string = u"cv2.bilateralFilter"
重现该行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.