![](/img/trans.png)
[英]AttributeError: 'Nonetype' object has no attribute '_info'
[英]AttributeError: 'NoneType' object has no attribute 'get_info'
这是在 Anime.py 文件下
import requests
import json
import random
from funcy import join
def anime():
def __init__(self):
self.url = f'https://animechan.vercel.app/api/quotes/character?name=saitama'
def get_info(self):
r = requests.get(self.url)
response = r.json()
join(response)
values_of_key = [a_dict["quote"] for a_dict in response]
return values_of_key
当我在 main() 中调用它时,出现 AttributeError: 'NoneType' object has no attribute 'get_info' 错误
import requests
import Anime
from Anime import anime
def main():
results = Anime.anime()
results.get_info()
print(results.get_info)
main()
您正在尝试使用一个类,但将其定义为一个不返回任何内容的函数。
您的代码应如下所示。
class anime():
def __init__(self):
self.url = f'https://animechan.vercel.app/api/quotes/character?name=saitama'
def get_info(self):
r = requests.get(self.url)
response = r.json()
join(response)
values_of_key = [a_dict["quote"] for a_dict in response]
return values_of_key
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.