Get attribute this way

Diez B. Roggisch deets at nospam.web.de
Tue Nov 17 03:20:44 EST 2009


King schrieb:
> "eval" can solve this problem right away but I am concerned about
> security issues. If not "eval" could you suggest something more
> efficient way. It won't be a big deal to change the format as
> application is still at development stage?

If you don't want to use eval (which is a good thing not to want), you'd 
end up (as Chris already told you) writing your own parser for python 
subexpressions. Which is laborous.

Or you create a XML-representation of these expressions, which saves you 
the parser, but not the evaluator, and bloats the XML. It could look 
like this:

<Connection>
    <node name="node1">
      <attribute name="gradient">
        <attribute name="colors">
          <item index="0" kind="int">
            <item index="1" kind="int"/>
          <... # close them all
    </node>
    <node ... # and the destination

</Connection>

Is this *really* all worth doing, or can't you just overcome your 
preconceptions - and use pickle, as it has been suggested to you before? 
Potentially with __getstate__/__setstate__ overridden for specific objects.


Diez



More information about the Python-list mailing list