Lists of attributes

Brian Quinlan brian at sweetapp.com
Fri Dec 7 03:46:40 CET 2001


Bruce wrote:
> Right, missed that. Now it's even cleaner:
> import random
> rgen = random.Random()
> flwrs = [Gladiolus(),Runuculus(),Chrysanthemum()]
> flowers = [rgen.choice(flwrs) for i in range(10)]
>
> This produces a random selection of references to only three
> objects.

I'm happy that you like the pattern, though your application seems a bit odd
:-)

> I'd still like to not have to explicity enumerate flwrs. I may play
> with Tim's suggestion:
>     class Flower(object):
> 	...
> and
>     Flower.__subclasses__()
>
> Except that I haven't been able to locate any actual information on
> how to get '__subclasses__()' to work.

__subclasses__ was added very recently (8 weeks, 3 days to be exact) so it
might not be in your Python build (when you start Python, it reports its
build date so you can check).

Cheers,
Brian





More information about the Python-list mailing list