can this b done

Gary Herron gherron at islandtraining.com
Thu Aug 3 03:22:06 EDT 2006


JyotiC wrote:
> hi,
>
> i hv a var of type IntVar, ca i get the name of this variable
>
> eg:-
> class someclass:
>      def somefun(...):
>            self.var=IntVar()
>             ....
>
>      def someotherfun(...):
>            in this fun can i get the name of var.
>            as in, can i get name var as a string 'var'
>
> Thanx
>
>   
Perhaps this will do what you want:

An instance of a class maintains a dictionary of all it's local 
variables. One of those will be self.var, but any other local variables 
will also be in the dictionary -- I have no idea how you plan to specify 
*which* local variable you want the name of.

Anyway, the dictionary is:
self.__dict__
and the list of variable names is the dictionary's keys:
self.__dict__.keys()
and one of the elements in that list will be the string:
'var'

Hope that helps:

Gary Herron







More information about the Python-list mailing list