Generators can only yield ints?

Medardo Rodriguez (Merchise Group) med.swl at
Sat Aug 23 01:03:57 CEST 2008

On Fri, Aug 22, 2008 at 6:44 PM, defn noob <circularfunc at> wrote:
> def letters():
>        a = xrange(ord('a'), ord('z')+1)
>        B = xrange(ord('A'), ord('Z')+1)
>        while True:
>                yield chr(a)
>                yield chr(B)
> TypeError: an integer is required

No. The problem is that "chr function" receives "int"
"a" and "B" are generators of "int" items.

What exactly you intent with that code?

def letters():
   for i in xrange(ord('a'), ord('z')+1):
       yield chr(i)
   for i in xrange(ord('A'), ord('Z')+1):
       yield chr(i)

for letter in letters():
   print letter


More information about the Python-list mailing list