Converting a string into an object instance

bowman bowman at montana.com
Sun Aug 15 15:07:50 EDT 1999


Given a string representation of an object, like you would get from
id(), is there anyway to get back the actual object? 

As background, in Tkinter, it is possible to create a menu, add
cascades, and then set the 'menu' attribute of a Toplevel object to that
menu, producing a menubar. If you then create another menu containing
the pulldown entries, you can attach this menu to the toplevel cascades
with

   topMenu.entryconfigure(index, menu=pullDown)

So far, so good. However, if you then want to walk the menu tree, 
	
   topMenu.entrycget(index, 'menu') 

will return a string such as .135753368.135845912, and not a copy of the
menu object.  This is indeed the same thing you get if you 'print
pullDown', but is not too useful for manipulating the attributes or
entries of the menu.

It is easy enough to just refer to the menu directly, but in some
instances it might be useful to have the ability to modify the 4th entry
in the 3rd cascade with only a reference to the top level object.

tia

-- 
Bear Technology  Making Montana safe for Grizzlies

http://people.montana.com/~bowman/




More information about the Python-list mailing list