简体   繁体   中英

Printing Object Attributes in Python

I've searched around Google and I'm unable to find a solution for what I'm trying to do. I'm sure there's one out there but seeing as how I'm new to Python I'm having a hard time getting this to work. I'm hoping someone can lead me in the right direction.

I'm trying to access TextMagic chats using their Python API. I can send messages without a problem but I can't print the chats.

Here is my code:

from textmagic.rest import TextmagicRestClient
from pprint import pprint

username = "username"
token = "password"
client = TextmagicRestClient(username, token)

chats, pager = client.chats.list()

pprint (chats)

result:

textmagic.rest.models.chats.Chat object at 0x7fb2ba0290d0,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029110,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029150,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029190,
textmagic.rest.models.chats.Chat object at 0x7fb2ba0291d0,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029210,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029250,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029290,
textmagic.rest.models.chats.Chat object at 0x7fb2ba0292d0,
textmagic.rest.models.chats.Chat object at 0x7fb2ba029310

What am I doing wrong?

Take a look at the textmagic-rest-python github.

There is a ChatMessages CollectionModel. Similar to the Chats collection you are currently looking at:

class ChatMessages(CollectionModel):
    instance = ChatMessage
    name = "chats"
    searchable = False

If you look here in the github respository you will see the implementation of the CollectionModel. It has several built in methods. One of them should list the instances of your "Chats" from there you should be able to get the message content with the '.text' attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM