I remember having this a while back, but this time it really flabbergasted me.
def iterator():
yield
it = iterator()
next(it)
next(it)
Or take this one.
next(i for i in range(0))
What should happen is this.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
But instead, nothing. It’s problem when this happens somewhere in your code.
def create_transform():
transform = cmds.createNode("transform", name="MyTransform")
next(i for i in range(0))
return transform
transform = create_transform()
print(transform)
# Error: name 'transform' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# NameError: name 'transform' is not defined #
It’s not defined, because that line never runs. An exception is thrown, silently, stopping the script.
Other exceptions run fine.
1/0
# Error: integer division or modulo by zero
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# ZeroDivisionError: integer division or modulo by zero #
Normally, you can instantiate an exception yourself, like this.
ZeroDivisionError
# Result: <type 'exceptions.ZeroDivisionError'> #
But guess what happens for StopIteration?
StopIteration
# Error: name 'StopIterationError' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# NameError: name 'StopIterationError' is not defined #
This is in Maya 2015 and 2018, and I bet it happens in other versions too. A native exception is undefined. What gives?
a = iter([1,2])
for i in range(4):
print i, next(a)0 1
1 2
2a = iter([1,2])
for i in range(4):
try:
print i, next(a)
except StopIteration:
print 'StopIteration'0 1
1 2
2 StopIteration
3 StopIteration--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e9c86276-76f3-48d3-bae9-db935b7cca60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e9c86276-76f3-48d3-bae9-db935b7cca60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC6mFDTZgewPjbNNofn-8J1w55Fk7B2w5PYa4M18i9s4g%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e9c86276-76f3-48d3-bae9-db935b7cca60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
i = iter([0,1])
for n in range(3):
print n, next(i)0 0
1 1
2i = iter([0,1])
for n in range(3):
try:
print n, next(i)
except Exception as e:
raise0 0
1 1
2# Error:
# Traceback (most recent call last):
# File "<maya console>", line 4, in <module>
# StopIteration # This appears to only happen in the Listener. In 2018, at least, if I try it in an imported Python module, it works as expected
Not for me, this is what initially bummed me out. My script got imported right, but one of the functions silently threw this exception and refused to continue. This was in 2018 on Windows.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e9c86276-76f3-48d3-bae9-db935b7cca60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC6mFDTZgewPjbNNofn-8J1w55Fk7B2w5PYa4M18i9s4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1fa24e23-3136-4aa2-9cac-e9440c83eefd%40googlegroups.com.