On Dec 17, 5:16 pm, Rominsky <john.romin...@gmail.com> wrote:
> 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
> ()?

The builtin functions "locals" and "globals" will both return a
dictionary whose keys are the variable names and values are the items
corresponding to those keys;

>>> locals()['b']
2.0
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to