python - How do I define a class where the arguments given to it on instantiation becomes its instance variables? -
I want to create a square where the properties of its frequency are defined immediately.
At first I thought I should do something like this,
class testdata (object): # through example http://stackoverflow.com/questions/2641484 / class-dict-self-init-args def __int___ (auto, * args, ** kwargs): super (testadata, self) .__ init (__) for arg in arg: self.arg = arg But this argument will not do the same property as self.arg and all arguments.
With revised comments with suggestions, I came to the solution that works for me:
class testdata (object): # http://stackoverflow.com/questions/2641484/class-dict-self-init-args def __init __ (self, * args, ** kwargs): Super (testadata, self) .__ init (__) (self) .__ dict __. Update for arg in args (kwargs): setattr (self, arg, arg) And if further characteristics are needed then can be added after urgency, which is (Instant, AGR, VAL)
Comments
Post a Comment