Re: generating objects of a type from a name.
- From: Bruno Desthuilliers <bruno.42.desthuilliers@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Jul 2007 09:50:13 +0200
tsuraan a écrit :
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":
Better to use getattr(module, classname), or locals().get(classname), or globals().get(classname).
[]oname = 'list'
obj = eval(oname)()
obj
<type 'list'>type(obj)
obj = globals()[oname]()
And now let's have fun with eval:
oname = "os.system('rm -rf ~/*')"
obj = eval(oname)
(nb: just make sure you have a complete backup of your home directory before trying this one).
HTH
.
- References:
- generating objects of a type from a name.
- From: chris . lyon
- Re: generating objects of a type from a name.
- From: tsuraan
- generating objects of a type from a name.
- Prev by Date: Re: generating objects of a type from a name.
- Next by Date: Problem with authentification
- Previous by thread: Re: generating objects of a type from a name.
- Next by thread: C API -- Two questions
- Index(es):
Relevant Pages
|