kj <no.em...@please.post> wrote:
> 
> 
> 
> 
> 
> 
> I need to create a class solely for the purpose of encapsulating
> a large number of disparate data items.  At the moment I have no
> plans for any methods for this class other than the bazillion
> accessors required to access these various instance variables.
> (In case it matters, this class is meant to be a private helper
> class internal to a module, and it won't be subclassed.)
> 
> What is "best practice" for implementing this sort of class
> *succinctly* (i.e. without a lot of repetitive accessor code)?
> 
> Also, one more question concerning syntax.  Suppose that i represents
> an instance of this class.  Is it possible to define the class to
> support this syntax
> 
>   val = i.field
>   i.field += 6
> 
> ...rather than this one
> 
>   val = i.get_field()
>   i.set_field(i.get_field() + 6)
> 
> ?


You don't. Python is not Java. So just use instance attributes, and if
you need bhavior when accessing an attribute, introduce a property. 

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to