You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
import srcomapi, srcomapi.datatypes as dt
import pandas as pd
api = srcomapi.SpeedrunCom(); api.debug = 1
test_df = pd.DataFrame(['Castlevania: Aria of Sorrow','Pokémon: Yellow'],columns=['Game'])
nb_games = len(test_df)
lb_per_game = []
#getting the game for each name
for i in range(nb_games):
try:
test_df.loc[i,'SRC_game'] = api.search(srcomapi.datatypes.Game, {"name": test_df.loc[i]['Game']})[0]
except IndexError:
pass
#collecting leaderboards for each game
for i in range(nb_games):
lb = {}
for category in test_df.loc[i,'SRC_game'].categories:
if not category.name in lb:
lb[category.name] = {}
if category.type == 'per-level':
pass
# if category.miscellaneous:
# pass
else:
lb[category.name] = dt.Leaderboard(api, data=api.get("leaderboards/{}/category/{}?embed=variables".format(test_df.loc[i,'SRC_game'].id, category.id)))
lb_per_game.append(lb)
for i in range(2):
game = lb_per_game[0]['Soma Any%'].game
platform = game.__getattr__('platforms')[0]
print(platform)
It raises a Type Error at the second time you enter the loop on second line :
object of type 'Platform' has no len()
File "C:\Users\charl\OneDrive\Documents\Projects\OWREstimator\srcdata.py", line 68, in <module>
platform = game.__getattr__('platforms')[0]
By inspecting the debugger, it seems the game.platforms attribute equals to this at this moment : 'Traceback (most recent call last):\n File "c:\\Users\\charl\\.vscode\\extensions\\ms-python.python-2021.6.944021595\\pythonFiles\\lib\\python\\debugpy\\_vendored\\pydevd\\_pydevd_bundle\\pydevd_resolver.py", line 193, in _get_py_dictionary\n attr = getattr(var, name)\n File "C:\\Users\\charl\\miniconda3\\lib\\site-packages\\srcomapi\\datatypes.py", line 46, in __getattr__\n if type(self.data[attr]) is list and len(self.data[attr]) > 0 and len(self.data[attr][0]) == 8:\nTypeError: object of type \'Platform\' has no len()\n'
(same for all not null attributes)
The text was updated successfully, but these errors were encountered:
cmnemoi
changed the title
Canaccess game attributes in a loop
Cannot access game attributes in a loop
Jun 20, 2021
So, given this code (for reproducibility) :
This piece of code works :
But this one does not :
It raises a
Type Error
at the second time you enter the loop on second line :By inspecting the debugger, it seems the
game.platforms
attribute equals to this at this moment :'Traceback (most recent call last):\n File "c:\\Users\\charl\\.vscode\\extensions\\ms-python.python-2021.6.944021595\\pythonFiles\\lib\\python\\debugpy\\_vendored\\pydevd\\_pydevd_bundle\\pydevd_resolver.py", line 193, in _get_py_dictionary\n attr = getattr(var, name)\n File "C:\\Users\\charl\\miniconda3\\lib\\site-packages\\srcomapi\\datatypes.py", line 46, in __getattr__\n if type(self.data[attr]) is list and len(self.data[attr]) > 0 and len(self.data[attr][0]) == 8:\nTypeError: object of type \'Platform\' has no len()\n'
(same for all not null attributes)
The text was updated successfully, but these errors were encountered: