如何修复这些错误代码
Traceback (most recent call last): File "/Users/erzajullian/PycharmProjects/Checker/topmail.py", line 9, in class checker_start(object): File "/Users/erzajullian/PycharmProjects/Checker/topmail.py", line 16, in checker_start print(checker_start().get_token()) NameError: name 'checker_start' is not defined
这是密码
import requests
from bs4 import BeautifulSoup
class output(object):
pass
class checker_start(object):
def get_token(self):
data = requests.get("https://mail.topmail.com/preview/mail/")
soup = BeautifulSoup(data.text, "lxml")
token_1 = soup.find("input", {"name": "form_token"})["value"]
return token_1
print(checker_start().get_token())
我的代码怎么了?在
您的
print(checker_start().get_token())
的行缩进错误。您正在尝试实例化类checker_start
的对象,并在类定义本身的代码块(作用域)中调用其方法get_token
。因此你得到一个NameError
。在Python中最显著的特性之一是带有缩进的代码块。在Python中,缩进代码不是样式问题(就像在大多数编程语言中一样),而是一种需求。在
尝试:
最后一行,
print(checker_start().get_token())
,缩进了一个级别,可能不应该这样。在相关问题 更多 >
编程相关推荐