getting object instead of string from dir()
david_v_wright at yahoo.com
Wed Dec 17 18:47:23 CET 2008
--- On Wed, 12/17/08, Rominsky <john.rominsky at gmail.com> wrote:
From: Rominsky <john.rominsky at gmail.com>
Subject: getting object instead of string from dir()
To: python-list at 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:
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
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.
More information about the Python-list