TelenkovDmitry 9 months ago
parent
commit
5a5b04a583
2 changed files with 33 additions and 1 deletions
  1. 11 1
      courses/python_oop/attr.py
  2. 22 0
      courses/python_oop/task.py

+ 11 - 1
courses/python_oop/common.py → courses/python_oop/attr.py

@@ -3,10 +3,19 @@ class Car:
     model = "BMW"
     engine = 1.6
 
+    def drive(self):
+        print("Let's go")
+
+
 class Person:
     name = 'Ivan'
     age = 30
 
+def test_method():
+    car = Car()
+    getattr(car, 'drive')()
+
+
 def teset_attr():
     car = Car()
     print(type(car))
@@ -91,7 +100,8 @@ def main():
     # teset_attr()
     # test_attr_2()
     # print(test_attr_3(Car, 'model'))
-    test_attr_4()
+    # test_attr_4()
+    test_method()
 
 if __name__ == '__main__':
     main()

+ 22 - 0
courses/python_oop/task.py

@@ -0,0 +1,22 @@
+class Config:
+    pass
+
+
+def create_instance(number: int):
+    obj = Config()
+    
+    for i in range(1, number+1):
+        name = 'attribute' + str(i)
+        value = 'value' + str(i)
+        setattr(obj, name, value)
+        
+    return obj
+
+
+def main():
+    config = create_instance(3)
+    print(config.__dict__)
+
+
+if __name__ == '__main__':
+    main()