Roy Smith schrieb:
In article <[EMAIL PROTECTED]>,
 "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

Also, I thought that part of the python philosophy was to allow any
sort of object in a list, and to allow the same methods to work with
whatever was in list.
Not really. When the usual argument about the existence (and justification) of lists & tuples comes along, one common distinction is that

- tuples contain arbitrary object of varying types, so they are kind of "records"
  - lists should contain uniform objects.

I see absolutely nothing wrong with lists of heterogenous types. Or, for that matter, iterators which generate heterogeneous types. Here's some perfectly reasonable examples (equally applicable to lists or iterators):

* The tokens parsed out of a file (ints, floats, identifiers, keywords, various kinds of punctuation, etc)

* The entries in a unix directory (plain files, directories, symlinks, special files, named sockets, etc)

* The vehicles going through a toll booth (cars, trucks, motorcycles)

I don't see any reason you shouldn't be able to build lists of those things.

When I wrote "uniform" I meant objects of the same kind. So for example subclasses are of course ok. And all of your examples are these: I want a Token-object, keeping file-location and possibly original string representation. The same goes for files - they are simply strings, their properties determined using stat-calls. And vehicles are... vehicles. So I'd create a common base-class for them, or made them at least behave proper through duck-typing. Which - for the case at hand - might include creating a __cmp__-method, based on horsepower or price-tag or...

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

Reply via email to