维基百科API。计数错误
Wikipedia API. Count error
我正在使用维基百科 API 包装器来解析页面中的数据。我的 lexus_count 函数有问题。那是计数函数的输出:
The Wikipedia page for 'List of Lexus_(vehicles)' has <function lexus_count at 0x0000020B039A8268> occurrences of the word 'Lexus'"
代码如下:
import wikipedia
print ("1: Searching Wikipedia for 'List of Lexus vehicles'")
try:
print (wikipedia.page('List of Lexus'))
print ('-' * 60)
except wikipedia.exceptions.DisambiguationError as e:
print (str(e))
print ('+' * 60)
print ('DisambiguationError: The page name is ambiguous')
print
print ("2: Searching Wikipedia for 'List of Lexus (vehicles)'")
print (wikipedia.page('List of Lexus_(vehicles)'))
print
result = wikipedia.page('List of Lexus_(vehicles)').content.encode('UTF8')
print ("3: Result of searching Wikipedia for 'List of Lexus vehicles_(vehicles)':")
print (result)
print
def lexus_count(vehicles):
lexus_count = result.count(vehicles)
print
print ("The Wikipedia page for 'List of Lexus_(vehicles)' has " + \
"{} occurrences of the word 'Lexus'".format(lexus_count))
print
我的计数函数有新问题。这是错误消息:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
D:\College\Python\Labs\lab 3\kaminski_lab3_p2.py in <module>()
30
31 print ("The Wikipedia page for 'List of Lexus_(vehicles)' has " + \
---> 32 "{} occurrences of the word 'Lexus'".format(lexus_count()))
33 print
TypeError: lexus_count() missing 1 required positional argument: 'lexus'
lexus_count
是一个函数。所以你必须调用它。
print ("The Wikipedia page for 'List of Lexus_(vehicles)' has " + \
"{} occurrences of the word 'Lexus'".format(lexus_count()))
我正在使用维基百科 API 包装器来解析页面中的数据。我的 lexus_count 函数有问题。那是计数函数的输出:
The Wikipedia page for 'List of Lexus_(vehicles)' has <function lexus_count at 0x0000020B039A8268> occurrences of the word 'Lexus'"
代码如下:
import wikipedia
print ("1: Searching Wikipedia for 'List of Lexus vehicles'")
try:
print (wikipedia.page('List of Lexus'))
print ('-' * 60)
except wikipedia.exceptions.DisambiguationError as e:
print (str(e))
print ('+' * 60)
print ('DisambiguationError: The page name is ambiguous')
print
print ("2: Searching Wikipedia for 'List of Lexus (vehicles)'")
print (wikipedia.page('List of Lexus_(vehicles)'))
print
result = wikipedia.page('List of Lexus_(vehicles)').content.encode('UTF8')
print ("3: Result of searching Wikipedia for 'List of Lexus vehicles_(vehicles)':")
print (result)
print
def lexus_count(vehicles):
lexus_count = result.count(vehicles)
print
print ("The Wikipedia page for 'List of Lexus_(vehicles)' has " + \
"{} occurrences of the word 'Lexus'".format(lexus_count))
print
我的计数函数有新问题。这是错误消息:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
D:\College\Python\Labs\lab 3\kaminski_lab3_p2.py in <module>()
30
31 print ("The Wikipedia page for 'List of Lexus_(vehicles)' has " + \
---> 32 "{} occurrences of the word 'Lexus'".format(lexus_count()))
33 print
TypeError: lexus_count() missing 1 required positional argument: 'lexus'
lexus_count
是一个函数。所以你必须调用它。
print ("The Wikipedia page for 'List of Lexus_(vehicles)' has " + \
"{} occurrences of the word 'Lexus'".format(lexus_count()))