【发布时间】:2021-11-13 00:07:57
【问题描述】:
我在 mypythonlib 目录中有一个文件 myfunctions.py
from requests_html import HTMLSession
import requests
def champs_info(champname:str, tier_str:int):
url = f"https://auntm.ai/champions/{champname}/tier/{tier_str}"
session = HTMLSession()
r = session.get(url)
r.html.render(sleep=1, keep_page=True, scrolldown=1)
information = r.html.find("div.sc-hiSbYr.XqbgT")
sig = r.html.find('div.sc-fbNXWD.iFMyOV')
tier_access = information[0]
tier = tier_access.text
我想通过另一个文件-test_myfunctions.py访问变量tier
但问题是我还必须为函数champs_info 提供参数,以便它可以相应地访问url。
from mypythonlib import myfunctions
def test_champs_info():
return myfunctions.champs_info("abomination",6).tier
但是在运行这段代码时,我得到了错误-
./tests/test_myfunctions.py::test_champs_info Failed: [undefined]AttributeError: 'NoneType' object has no attribute 'tier'
def test_champs_info():
> return myfunctions.champs_info("abomination",6).tier
E AttributeError: 'NoneType' object has no attribute 'tier'
tests/test_myfunctions.py:3: AttributeError
对此有任何解决方案,为什么此代码无法访问该变量?
我写了myfunctions.champs_info("abomination",6).tier,希望它能从champs_info函数中获取tier变量,同时从myfunctions文件中提供所有所需的参数:(
【问题讨论】:
标签: python function nested-function