staticmethod and __call__

Luigi Ballabio ballabio at mac.com
Fri Dec 7 15:43:39 EST 2001


Bruce,

At 7:04 AM -0800 12/7/01, Bruce Eckel wrote:
>I suppose a generator could be thought of as a special case of a
>factory, but it's generally considered a different kind of entity.

I agree. The problem is, a "generator" in Python 2.2 is a well defined
concept and your previous implementation doesn't fit. In that framework,
an item generator would be something like:

def ItemGenerator():
     import random
     rgen = random.Random()
     items = [j for j in vars(Item).values() if isinstance(j, Item)]
     while 1:
         yield rgen.choice(items)

gen = ItemGenerator()
items = [gen.next() for i in range(5)]

Bye,
	Luigi

-- 




More information about the Python-list mailing list