我在Windows 7上安装了Python 3.6.2版,我收到以下错误:
TypeError:'>' 'method-wrapper'和'int'
的实例之间不支持
我该如何解决这个问题?
# create a subclass and override the handler methods
class MyHTMLParser(HTMLParser):
# function to handle an opening tag in the doc
# this will be called when the closing ">" of the tag is reached
def handle_starttag(self, tag, attrs):
pos = self.getpos() # returns a tuple indication line and character
print ("At line: ", pos[0], " position ", pos[1])
if attrs. __len__ > 0:
print ("\tAttributes: ")
for a in attrs:
print ("\t", a[0], "=", a[1])
答案 0 :(得分:2)
首先__len__
不是属性,它是一种方法,您需要像这样调用它:attrs.__len__()
。但是,当有一个非常好的方法时,为什么要调用dunder方法 - len
- 哪个更易于使用并且需要更少的字符?
if len(attrs):
...