String To Dict Problem

Felipe Almeida Lessa felipe.lessa at gmail.com
Fri Apr 21 22:37:28 EDT 2006


Em Sex, 2006-04-21 às 18:40 -0700, Clodoaldo Pinto escreveu:
> Only a small problem when I try to evaluate this:
> 
> safe_eval('True')

Change

    def visitName(self,node, **kw):
        raise Unsafe_Source_Error("Strings must be quoted", 
                                 node.name, node)

To
    otherNames = {
        'True': True,
        'False': False,
        'None': None
    }

    def visitName(self, node, **kw):
        name = node.name
        try:
            return self.__class__.otherNames[name]
        except KeyError:
            raise Unsafe_Source_Error("Strings must be quoted", 
                                      name, node)


-- 
Felipe.




More information about the Python-list mailing list