Py学习  »  Python

只有一个参数时Python抛出多个参数错误

Onur Ozbek • 5 年前 • 1508 次点击  

我在另一个类中调用一个方法,得到以下错误。这是声明定义方法的类:

from web import Web
import ast


class WebCrawler:
    web = Web()

    def crawl(self):
        root = self.root()
        URL = ast.literal_eval(self.get(root))
        return URL

这个类称之为:

from web import Web
from crawler import WebCrawler

web = Web()
crawler = WebCrawler()
urls = crawler.crawl(web)

print(urls)

Traceback (most recent call last):
  File "/home/onur/Desktop/web-crawler/test-run.py", line 6, in <module>
    urls = crawler.crawl(web)
TypeError: crawl() takes 1 positional argument but 2 were given
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54380
 
1508 次点击  
文章 [ 1 ]  |  最新文章 5 年前