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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -