Instance attributes vs method arguments

John O'Hagan mail at johnohagan.com
Tue Nov 25 22:45:26 EST 2008


On Wed, 26 Nov 2008, Ben Finney wrote:
> John O'Hagan <mail at johnohagan.com> writes:
> > insofar as one is only interested in accessing methods, is there an
> > difference in efficiency (for large enough number of methods and
> > arguments) between
> >
> > a) passing all arguments to __init__() and accessing them via self
> > within individual methods:
> >
> > class = Class(all_class_args)
> > class.method_a()
> > class.method_b()
> > ...
> > or
> >
> > b) passing the arguments needed by each method when it is called on
> > an instance:
> >
> > class = Class()
> > class.method_a(a_args)
> > class.method_b(b_args)
> > ...
>
> Note that you've chosen confusing names for the above. When you call
> the class, the return value will be an *instance of* the class, so
> binding the name ‘class’ to that return value has two problems: it's a
> misnomer, and it's a syntax error because ‘class’ is a reserved word.

I know, sorry, just a simplified example...s/class/class_instance/.

John





More information about the Python-list mailing list