Explorar o código

attr from string test

Johann Woelper %!s(int64=9) %!d(string=hai) anos
pai
achega
da9744450a
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  1. 11 0
      attr_from_string.py

+ 11 - 0
attr_from_string.py

@@ -0,0 +1,11 @@
+class Test():
+    def __init__(self):
+        self.val = None
+
+    def setByString(self, string, value):
+        self.__dict__[string] = value
+    
+
+t = Test()
+t.setByString('val', 1)
+print t.__dict__