Python Forum

Full Version: How to get data instead of memory addresses
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to extract and display data from an API.  I'm using a purpose-built wrapper that utilizes SQLAlchemy, which I have installed.  But instead of getting the actual data, the script I wrote gives me a series of memory addresses.  Do I need to do a database setup or something for the program to show me the actual data?

My code:
from cassiopeia import riotapi
riotapi.set_region("NA")
riotapi.set_api_key("********************")
summoner = riotapi.get_summoner_by_name("KBingo")
championlist = riotapi.get_champions()

print(summoner.name)
print(championlist)
Output:
== RESTART: C:\Program Files (x86)\Python36-32\LoL masteries by summoner.py ==
KBingo
[<cassiopeia.type.core.staticdata.Champion object at 0x050C90B0>, <cassiopeia.type.core.staticdata.Champion object at 0x050C90D0>, <cassiopeia.type.core.staticdata.Champion object at 0x049ADDF0>, <cassiopeia.type.core.staticdata.Champion object at 0x049ADD50>, 
etc.
Obviously championlist is list of Champion objects. So you need to iterate over it and print what you want.

e.g.

for champion in championlist: # or use riotapi.get_champions() instead of championlist
    print(champion)
for champion in championlist: # or use riotapi.get_champions() instead of championlist
    print(champion.name)
championlist = [champion.name for champion in riotapi.get_champions()]
print(championlist)
any of the above examples would print champion names.
As buran points out, the data you are getting is a list of objects.When you print a list, it prints the repr() of each item in the list. The default repr() is the class of the object and the memory location of the object. So you are getting the actual data, it just looks like you are getting a bunch of memory addresses.
That worked. Thank you!