turning a string into an object name
Philip Swartzleonard
starx at pacbell.net
Sat Apr 6 18:15:27 EST 2002
Chris Liechti || Thu 04 Apr 2002 11:51:30a:
> netzapper at magicstar.net (A. Jones) wrote in
> news:3cac943f.132176618 at mammoth.usenet-access.com:
>
>> On Thu, 04 Apr 2002 11:56:24 GMT, Alex Martelli <aleax at aleax.it>
>> wrote:
>>
>> Furthermore, you can wrap it inside a class.
>>
>> class test:
>> def wrongHeaded(self, name, value):
>> exec "self."+name+'='+repr(value)
>> print vars()
>>
>> this produces no exceptions, and doesn't cause any problems, since
>> vars is never defined... only self.vars is.
>
> until someone has the idea to pass some fancier names like
> t.wrongHeaded('a; del None', 57)
>
> and then have fun watching your entire program fail...
Hm, i think you want something like
t.wrongHeaded('a=5; del None;b', 57)
which will evaluate to
self.a=5; del None; b=57
instead of
self.a; del None=57
which is two syntax errors in one (no a defined, and i think 'del none=
57' is invalid?)
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list