首页 > 解决方案 > 如何通过在 python 中使用 rawgpy 包装器通过流派获取游戏名称?

问题描述

这是我获取与赛车类型相关的游戏列表的代码我试图在 python 中使用 jupyter 访问游戏名称我已经使用 anaconda 提示安装了库但是当我运行代码时出现此错误。

import rawgpy
from rawgpy import data_classes
results= data_classes.charts.GenreChart("racing")
game = results[0]
game.populate()` 
AttributeError: module 'rawgpy.data_classes' has no attribute 'charts'
Can someone please help mw with this error

标签: pythonapiwrapper

解决方案


您可以在此处查看包的源代码。

我不熟悉这个库,但只要阅读您的问题并浏览代码,我可以肯定地说 python 模块data_classes中没有调用符号/变量charts。导入依赖项的方式是尝试导入__init__.py导入符号文件中的所有内容,但遗憾的是,维护者似乎不知道如何使用这些文件;如果该变量存在,它将在data_classes模块的 init 文件中,而事实并非如此。

您应该能够通过执行以下操作来解决您的问题:

import rawgpy
from rawgpy.data_classes.charts import GenreChart
results= GenreChart("racing")
game = results[0]
game.populate()

推荐阅读