Python Forum
How to get data instead of memory addresses
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get data instead of memory addresses
#1
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.
Reply
#2
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.
Reply
#3
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
That worked. Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  a function to get IP addresses of interfaces Skaperen 2 1,428 May-30-2022, 05:00 PM
Last Post: Skaperen
  Loop through list of ip-addresses [SOLVED] AlphaInc 7 3,988 May-11-2022, 02:23 PM
Last Post: menator01
  instance methods sharing addresses mim 1 2,247 Mar-28-2021, 05:22 AM
Last Post: deanhystad
  Convert email addresses to VCF format jehoshua 2 4,689 Mar-06-2021, 12:50 AM
Last Post: jehoshua
  crunching ip addresses snichols 5 2,812 Nov-10-2020, 05:24 PM
Last Post: snichols
  extract email addresses from gmail vigneshboolog 0 1,772 Feb-11-2020, 09:23 AM
Last Post: vigneshboolog
  Extract email addresses from string and store them in a list oslosurfer 2 2,712 Nov-24-2019, 03:35 PM
Last Post: oslosurfer
  Read list of IP addresses from file and return a network dflick 4 4,896 Oct-27-2018, 09:33 AM
Last Post: buran
  Help required to print MAC addresses anna 50 20,523 Feb-22-2018, 09:53 AM
Last Post: anna
  How do I get coordinates for addresses from the csv list? BigD 6 7,863 Dec-02-2017, 09:38 PM
Last Post: BigD

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020