Use of __slots__

Crutcher crutcher at gmail.com
Sun Feb 26 17:28:07 EST 2006


Steven is right, however, there is a way:

def new_record(slotlist):
  class R(object):
    __slots__ = slotlist
  return R()

record1 = new_record(["age", "name", "job"])
record1.age = 27
record1.name = 'Fred'
record1.job = 'Plumber'
record1.salary = 50000




More information about the Python-list mailing list