[pyar] Uso eval() para clase definida en otro archivo

Marcos Dione mdione en grulic.org.ar
Vie Mar 3 19:44:55 ART 2017


On Fri, Mar 03, 2017 at 04:53:57PM -0300, Juan Pablo Hernández Vogt wrote:
> class BaseObject(object):
>     def __init__(self, parameters=None):
>         self.parameters = parameters
> 
>         # Derived classes from other files must set its environment
>         # in order to be able to execute eval() correctly.
>         self.globals = None
> 
>     def load_parameter(self, key, value):
>         if not self.parameters:
>             self.parameters = {}
> 
>         self.parameters[key] = eval(value, self.globals)

    NO

    USES

    eval(). 

    mirá mi respuesta anterior y la de Facundo.

-- 
(Not so) Random fortune:
Terrorism isn't a crime against people or property. It's a crime against
our minds, using the death of innocents and destruction of property to
make us fearful.
	    -- Bruce Schneier


Más información sobre la lista de distribución pyar