Getting current variable name

Daniel Dittmar daniel.dittmar at sap.corp
Wed Mar 16 09:51:57 EST 2005


pl wrote:
> I have to get some list variable names at some point in my program. So
> I ended up looking into globals() to get them with a small function like
> this:
[...]
> 	var = globals().keys()
> 	for i in var :
> 		if globdict[i] == obj:
> 			print i

Use 'is' instead of '=='. This will return true if the arguments are the 
same object:
 >>> l1 = [1, 2, 3]
 >>> l2 = [1, 2, 3]
 >>> l1 == l2
True
 >>> l1 is l2
False

Daniel



More information about the Python-list mailing list