Skip to content
This repository was archived by the owner on Sep 15, 2023. It is now read-only.
This repository was archived by the owner on Sep 15, 2023. It is now read-only.

Cannot access game attributes in a loop #19

@cmnemoi

Description

@cmnemoi

So, given this code (for reproducibility) :

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)

This piece of code works :

platform = lb_per_game[0]['Soma Any%'].game.__getattr__('platforms')[0]
 print(platform)

But this one does not :

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions