main
main copied to clipboard
Unpacking a class that contains __iter__ into the __future__ print function fails
I have a class that overrides __iter__ to allow me to unpack it like a tuple. It works just fine on CPython 2.7.8 but fails on IronPython 2.7.5.
As seen below the Error is:
TypeError: print() argument after * must be a sequence, not Object_1$1
The console output below is me trying it on CPython then Ironpython.
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import register
>>> a = register.Register(0,0,0)
>>> from __future__ import print_function
>>> print(*a)
0 0 0
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.18408 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import register
>>> from __future__ import print_function
>>> a = register.Register(0,0,0)
>>> print(*a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: print() argument after * must be a sequence, not Object_1$1
If I call __iter__ manually then it works.
>>> print(*a.__iter__())
0 0 0
You can try it out with the following code (copied from IDLE).
>>> class me(object):
def __init__(self):
self.a=1
self.b=2
self.c=3
def __iter__(self):
for value in (self.a, self.b, self.c):
yield value
>>> a = me()
>>> print(*a)
1 2 3
It will fail through IronPython.
EDIT: Seems to only be an issue with the print function. I can unpack into function other than print.