![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
20/02/2013, 18:31
|
![Avatar de razpeitia](http://static.forosdelweb.com/customavatars/avatar93893_5.gif) | Moderador | | Fecha de Ingreso: marzo-2005 Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 10 meses Puntos: 1360 | |
Respuesta: python convertir string a callable o funcion o metodo getattr
Código Python:
Ver originalclass A: def __init__(self, a): self.a = a def some_method(self): print self.a x = A('a') y = A('b') s = getattr(x, 'some_method') s() s = getattr(y, 'some_method') s() try: s = getattr(y, 'no_method') except AttributeError: print "no_method no es un atributo"
|