簡體   English   中英

AttributeError:“NoneType”對象沒有屬性“get_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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM