[Tutor] class arguments?
kent37 at tds.net
Fri Jan 23 12:45:04 CET 2009
On Fri, Jan 23, 2009 at 6:04 AM, spir <denis.spir at free.fr> wrote:
> Thank you Alan and sorry for not having been clear enough. The point actually was class (definition) attributes. I thought at e.g. Guido's views that lists were for homogeneous sequences as opposed to tuples rather like records. And a way to ensure sich a homogeneity, in the sense of items beeing of the same type or super type.
> The straightforward path to ensure that, as I see it, is to add proper argument to a class definition.
A simple way to do this is with a class factory function, for example:
def makeMonoList(typ, number):
item_type = type
item_number = number
IntegerList = makeMonoList(int, 5)
myIntegerList = IntegerList()
This is similar in spirit to collections.namedtuple() in Python 2.6
though the implementation is different; namedtuple() actually creates
and evaluates the text of the new class definition:
More information about the Tutor