Search code examples
pythonintrospectioninspect

Python, listing the attributes of a parameter


This question may be a little green.

In the example below, I am trying to find out a list of the attribtues from the "message" parameter.

@respond_to("^meow")
def remind_me_at(self, message):
    fre = "asd: %s " % str(message.sender)
    fre = "asd: %s " % str(message.mention_name)
    fren = "asd: %s " % str(message.sender.name)
    #fren = "hello, %s!" % str(message)
    self.say(fren, message=message)
    self.say(fre, message=message)

As there is no documentation but the code is opensource, how can I find the file where the method is implemented efficiently; even if the class is in a library file.

[[Update]] I found this solution on another thread asking the question in a different way

[(name,type(getattr(math,name))) for name in dir(math)]

Solution

  • Use the dir() built-in function. It returns a list of all attributes of an object.

    print dir(message)