How to automate accessor definition?

kj no.email at please.post
Sat Mar 20 18:15:54 EDT 2010







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)

?

TIA!

~K



More information about the Python-list mailing list