[Bf-committers] Patch: removing use of exec() and eval() from python source

Martin Poirier theeth at yahoo.com
Wed Oct 21 00:32:10 CEST 2009


--- On Tue, 10/20/09, Mathias Panzenböck <grosser.meister.morti at gmx.net> wrote:

> > 
> > Even if the code is not changed to use the rna lookup
> function I think it should
> > still be changed this way:
> > exec("context.%s='%s'" % (self.path, self.value))
> > ->
> > exec("context.%s=%r" % (self.path, self.value))
> >
> > ...
> > 
> > Or in case python >= 2.5 can be assumed:
> > exec("context.%s = %r if context.%s!=%r else %r" %
> (self.path, self.value_2,
> > self.path, self.value_2, self.value_1))
> > 
> 
> It just occurred to me that it should be possible to
> write:
> exec("context.%s = self.value" % self.path)
> 
> and:
> exec("context.%s = self.value_2 if context.%s!=self.value_2
> else self.value_1" %
> (self.path, self.path))
> 
> Which prevents the unnecessary conversion to and from
> strings of the values.

The operator properties need to be defined with a specific type, evaluating the value means it can convert to whatever type is needed from a string property.

Martin


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/


More information about the Bf-committers mailing list