简体   繁体   English

Python - help()命令 - 相同的字符串不同的结果

[英]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? 所以如果它是相同的字符串,那么帮助不应该返回相同的字符串?

  1. title is a unicode object. title是一个unicode对象。
  2. Therefore "cv2." + title + "" 因此"cv2." + title + "" "cv2." + title + "" is also a unicode object. "cv2." + title + ""也是一个unicode对象。
  3. help apparently only accepts non-unicode str s for looking up names, such as string2 . help显然只接受非unicode str来查找名称,例如string2
  4. So string and string2 are in fact different types, but str and unicode can still compare equal. 所以stringstring2实际上是不同的类型,但strunicode仍然可以比较相等。
  5. You can reproduce the behaviour with title = u'bilateralFilter' or string = u"cv2.bilateralFilter" . 您可以使用title = u'bilateralFilter'string = u"cv2.bilateralFilter"重现该行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM