--- On Wed, 12/17/08, Rominsky <john.romin...@gmail.com> wrote:
From: Rominsky <john.romin...@gmail.com> Subject: getting object instead of string from dir() To: python-list@python.org Date: Wednesday, December 17, 2008, 12:16 PM I am trying to use dir to generate a list of methods, variables, etc. I would like to be able to go through the list and seperate the objects by type using the type() command, but the dir command returns a list of strings. When I ask for the type of an element, the answer is always string. How do I point at the variables themselves. A quick example is: a = 5 b = 2.0 c = 'c' lst = dir() for el in lst: print type(el) Right now I am understandably getting all types being output as strings, how do i get the type of the actual objects returned from dir ()? -- http://mail.python.org/mailman/listinfo/python-list Forgive me if you are well aware of this, just thought i'd chime in with the "Duck typing speech": Pythonic programming style that determines an object's type by inspection of its method or attribute signature rather than by explicit relationship to some type object ("If it looks like a duck and quacks like a duck, it must be a duck.") By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type() or isinstance(). Instead, it typically employs the EAFP (Easier to Ask Forgiveness than Permission) style of programming. http://en.wikipedia.org/wiki/Duck_typing -- http://mail.python.org/mailman/listinfo/python-list