Generators can only yield ints?
Medardo Rodriguez (Merchise Group)
med.swl at gmail.com
Fri Aug 22 19:03:57 EDT 2008
On Fri, Aug 22, 2008 at 6:44 PM, defn noob <circularfunc at yahoo.se> 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?
Maybe:
#<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
#</code>
Regards
More information about the Python-list
mailing list