[SOLVED] trying to see a list but it only says <store.Person object ...> ???

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
ninjaK4T_06
Newbie
Posts: 6
Joined: Fri Nov 30, 2018 6:19 am
Contact:

[SOLVED] trying to see a list but it only says <store.Person object ...> ???

#1 Post by ninjaK4T_06 » Fri Nov 30, 2018 6:36 am

I'm using this post to make random characters, but every time I try to see them by just putting-

Code: Select all

label start:
    "[random_characters]"
it poops this out into the textbox:

Code: Select all

[<store.Person object at0x0ED2 5FF0>, <store.Person object at 0x0ED2 5A30>, ... ] 
and it goes on 5 total times, since that's how many characters I'm trying to make.

I read this, specifically Milkymalk's long answer; I think that's what is my problem is, but I am very newb so I'm don't to know how to solve it >_<'''

So I would very much appreciate help!
Last edited by ninjaK4T_06 on Fri Nov 30, 2018 7:30 am, edited 1 time in total.

User avatar
Remix
Eileen-Class Veteran
Posts: 1441
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: trying to see a list but it only says <store.Person object ...> ???

#2 Post by Remix » Fri Nov 30, 2018 7:06 am

amend Person to include a __repr__ (or __str__ if you prefer)

Code: Select all

    class Person(object):

        def __init__(self, name, gender, age):

            self.name = name
            self.gender = gender
            self.age = age

        def __repr__(self):
            return "Person: ({}, {}, {})".format(
                self.name,
                self.gender,
                self.age )
You might also want a !q in your interpolation (to escape any braces) "[random_characters!q]"
Frameworks & Scriptlets:

ninjaK4T_06
Newbie
Posts: 6
Joined: Fri Nov 30, 2018 6:19 am
Contact:

Re: trying to see a list but it only says <store.Person object ...> ???

#3 Post by ninjaK4T_06 » Fri Nov 30, 2018 7:28 am

Remix wrote:
Fri Nov 30, 2018 7:06 am
amend Person to include a __repr__ (or __str__ if you prefer)

Code: Select all

    class Person(object):

        def __init__(self, name, gender, age):

            self.name = name
            self.gender = gender
            self.age = age

        def __repr__(self):
            return "Person: ({}, {}, {})".format(
                self.name,
                self.gender,
                self.age )
You might also want a !q in your interpolation (to escape any braces) "[random_characters!q]"
This worked perfectly, thank you very much!! :D

User avatar
trooper6
Lemma-Class Veteran
Posts: 3706
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: trying to see a list but it only says <store.Person object ...> ???

#4 Post by trooper6 » Fri Nov 30, 2018 4:56 pm

Remix wrote:
Fri Nov 30, 2018 7:06 am
You might also want a !q in your interpolation (to escape any braces) "[random_characters!q]"
Hey Remix! I tried to google it, but !q is not particularly easy to google. Could you explain !q a bit more? When exactly would one want to use this and how does it work?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Remix
Eileen-Class Veteran
Posts: 1441
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: trying to see a list but it only says <store.Person object ...> ???

#5 Post by Remix » Fri Nov 30, 2018 5:24 pm

trooper6 wrote:
Fri Nov 30, 2018 4:56 pm
Remix wrote:
Fri Nov 30, 2018 7:06 am
You might also want a !q in your interpolation (to escape any braces) "[random_characters!q]"
Hey Remix! I tried to google it, but !q is not particularly easy to google. Could you explain !q a bit more? When exactly would one want to use this and how does it work?
Of course:

Imagine you had:

Code: Select all

default my_dict = {'a':1, 'b':2, 'c':3}

label start:

    "[my_dict]"
Result:
Exception: Unknown text tag u"u'a': 1, u'c': 3, u'b': 2"

This is because Ren'Py does the interpolation before it does formatting and characters like { and % (and maybe others) are thought to be text tags, format identifiers or the like.
Rather than doing $ my_dict_output = str(my_dict).replace('{', {{').replace('%', '%%') we just add the !q after our variable name and Ren'Py does the clever stuff for us.

More: https://www.renpy.org/dev-doc/html/text ... ating-data
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users