Guest User

Untitled

a guest
Apr 1st, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import inspect
  2.  
  3.  
  4. class Napraw(object):
  5.  
  6.     def __init__(self, m, b):
  7.         super().__init__()
  8.         self.m = m
  9.         self.b = b
  10.  
  11.  
  12. class Tagi(object):
  13.     m = None
  14.     b = None
  15.  
  16.     def __init__(self):
  17.         super().__init__()
  18.  
  19.     # tylko argumenty inne niż None będą przypisane do atrybutu obiektu
  20.     def setup(self, m=None, b=None):
  21.         args, _, _, _ = inspect.getargvalues(inspect.currentframe())
  22.         for arg in args:
  23.             if locals()[arg] is not None:
  24.                 setattr(self, arg, locals()[arg])
  25.  
  26.     @classmethod
  27.     def with_args(cls, m, b):
  28.         o = cls()
  29.         o.setup(m, b)
  30.         return o
Advertisement
Add Comment
Please, Sign In to add comment