best way to get data into a new instance?

Fredrik Lundh fredrik at pythonware.com
Thu Sep 28 17:27:15 CEST 2006


John Salerno wrote:

> So I'm wondering, is the best way to get all this information into the 
> object to just have a really long __init__ method that takes each argument?

really long __init__ argument lists only work if most argument have 
reasonable defaults, and you're prepared to use keyword arguments when 
creating the objects.  and don't mind writing the field names over and 
over and over and over again.

really long positional argument lists are really bad; it's way too easy 
to mess up the order, and end up stuffing the wrong thing in the wrong 
field.

there's no need to use this if you're using the class as a "record"; 
just set the relevant attributes and be done with it.

(see the "simulate UI" part of my code example for how to do that).

</F>




More information about the Python-list mailing list