generating objects of a type from a name.

tsuraan tsuraan at gmail.com
Thu Jul 26 20:59:00 EDT 2007


I'm not sure what a visual object is, but to create an instance of an
object whose name is known, you can use "eval":

>>> oname = 'list'
>>> obj = eval(oname)()
>>> obj
[]
>>> type(obj)
<type 'list'>

Hope that helps!


On 26/07/07, chris.lyon at spritenote.co.uk <chris.lyon at spritenote.co.uk> wrote:
> I'm trying to generate visual python objects from django objects and
> therefore have objects called  'Ring' and 'Cylinder' as django objects
> and I want to create objects of those names in visual.
> I can cludge it in varius ways by using dir and lots of if lookups but
> is there a  way of doing this that allows the name to generate a
> visual object of the appropriate name or fail nicely if the visual
> object doesn't exist?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list