首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python Wikipedia API。Count函数

Python Wikipedia API。Count函数
EN

Stack Overflow用户
提问于 2017-02-25 03:16:37
回答 1查看 605关注 0票数 0

我正在使用Python库Wikipedia API来解析来自Wikipedia的数据。我正在获取TypeError on count函数。

代码如下:

代码语言:javascript
复制
 import wikipedia

'Searching Wikipedia for List of Lexus vehicle

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

搜索雷克萨斯汽车:

代码语言:javascript
复制
print ("2: Searching Wikipedia for 'List of Lexus (vehicles)'")
print (wikipedia.page('List of Lexus_(vehicles)'))
print

打印结果:

代码语言:javascript
复制
 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

Count函数:

代码语言:javascript
复制
 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消息:

代码语言:javascript
复制
---------------------------------------------------------------------------
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: 'vehicles'

现在我遇到了新的问题NameError:

代码语言:javascript
复制
---------------------------------------------------------------------------
NameError                                 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(vehicles)))
     33 print

NameError: name 'vehicles' is not defined

更新输出中不可读的输出部分:

代码语言:javascript
复制
The Wikipedia page for 'List of Lexus_(vehicles)' has <function lexus_count at 0x000002431D2B28C8> occurrences of the word 'Lexus'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-25 03:22:57

lexus_count()接受参数载体,但您忘记将其传递给第32行的函数

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42446584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档