Re: [Maya-Python] StopIteration, where art thou?

2017-10-12 Thread Marcus Ottosson
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.
​

On 12 October 2017 at 06:50, Robert White  wrote:

> Huh, that is super weird.
>
> I'm getting the same behavior. It probably has something to do with how
> maya is exec-ing the listener. Clearly it is throwing the exception, it
> just getting swallowed somewhere along the way. Maybe the for loop is
> grabbing it? execution does stop though.
>
> Really weird.
>
>
> On Wednesday, October 11, 2017 at 10:30:35 PM UTC-5, Michael Boon wrote:
>>
>> I'm on Windows. To clarify though, it's not about StopIteration being
>> available (except in 2015, apparently). It's about StopIteration being
>> silently caught. 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. I
>> don't know what would happen in external editors.
>>
>> To add to the confusion, if you catch and raise the exception, it works.
>> This
>> i = iter([0,1])
>> for n in range(3):
>> print n, next(i)
>> fails silently:
>> 0 0
>> 1 1
>> 2
>>
>> While this
>> i = iter([0,1])
>> for n in range(3):
>> try:
>> print n, next(i)
>> except Exception as e:
>> raise
>> shows the unhandled exception:
>> 0 0
>> 1 1
>> 2# Error:
>> # Traceback (most recent call last):
>> #   File "", line 4, in 
>> # StopIteration #
>>
>>
>> On Thursday, 12 October 2017 08:09:43 UTC+11, Robert White wrote:
>>>
>>> I can see StopIteration just fine in 2018 on windows.
>>>
>>> It should live in both __builtins__ and the exceptions module.
>>> Maybe some other script is messing those up?
>>>
>>> On Wednesday, October 11, 2017 at 3:23:57 PM UTC-5, Justin Israel wrote:

 Is this only in Windows? I just tested 2016, 2017, and 2018. They all
 have StopIteration available.

 On Tue, Oct 10, 2017 at 7:40 PM Marcus Ottosson 
 wrote:

> Can confirm that it is defined in 2018 as well. The above was in 2015.
> How peculiar.
>
> On 10 October 2017 at 07:22, Michael Boon  wrote:
>
>> Wow! Happens in 2016 too.
>> However, StopIteration is defined, and I can catch it.
>>
>> This:
>> a = iter([1,2])
>> for i in range(4):
>> print i, next(a)
>> gives
>> 0 1
>> 1 2
>> 2
>>
>> While this:
>> a = iter([1,2])
>> for i in range(4):
>> try:
>> print i, next(a)
>> except StopIteration:
>> print 'StopIteration'
>> gives
>> 0 1
>> 1 2
>> 2 StopIteration
>> 3 StopIteration
>>
>>
>> On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:
>>>
>>> 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 "", line 1, in 
>>> 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 "", line 1, in # 
>>> 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 "", line 1, in # 
>>> ZeroDivisionError: integer division or modulo by zero #
>>>
>>> Normally, you can instantiate an exception yourself, like this.
>>>
>>> ZeroDivisionError# Result:  #
>>>
>>> But guess what happens for StopIteration?
>>>
>>> StopIteration# Error: name 'StopIterationError' is not defined# 
>>> Traceback (most recent call last):#   File "", line 1, in 
>>> # 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?
>>> ​
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Python Programming for Autodesk Maya" group.
>> To 

Re: [Maya-Python] StopIteration, where art thou?

2017-10-11 Thread Robert White
Huh, that is super weird.

I'm getting the same behavior. It probably has something to do with how 
maya is exec-ing the listener. Clearly it is throwing the exception, it 
just getting swallowed somewhere along the way. Maybe the for loop is 
grabbing it? execution does stop though.

Really weird.


On Wednesday, October 11, 2017 at 10:30:35 PM UTC-5, Michael Boon wrote:
>
> I'm on Windows. To clarify though, it's not about StopIteration being 
> available (except in 2015, apparently). It's about StopIteration being 
> silently caught. 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. I 
> don't know what would happen in external editors.
>
> To add to the confusion, if you catch and raise the exception, it works.
> This
> i = iter([0,1])
> for n in range(3):
> print n, next(i)
> fails silently:
> 0 0
> 1 1
> 2
>
> While this
> i = iter([0,1])
> for n in range(3):
> try:
> print n, next(i)
> except Exception as e:
> raise
> shows the unhandled exception:
> 0 0
> 1 1
> 2# Error: 
> # Traceback (most recent call last):
> #   File "", line 4, in 
> # StopIteration # 
>
>
> On Thursday, 12 October 2017 08:09:43 UTC+11, Robert White wrote:
>>
>> I can see StopIteration just fine in 2018 on windows.
>>
>> It should live in both __builtins__ and the exceptions module. 
>> Maybe some other script is messing those up?
>>
>> On Wednesday, October 11, 2017 at 3:23:57 PM UTC-5, Justin Israel wrote:
>>>
>>> Is this only in Windows? I just tested 2016, 2017, and 2018. They all 
>>> have StopIteration available.
>>>
>>> On Tue, Oct 10, 2017 at 7:40 PM Marcus Ottosson  
>>> wrote:
>>>
 Can confirm that it is defined in 2018 as well. The above was in 2015. 
 How peculiar.

 On 10 October 2017 at 07:22, Michael Boon  wrote:

> Wow! Happens in 2016 too.
> However, StopIteration is defined, and I can catch it.
>
> This:
> a = iter([1,2])
> for i in range(4):
> print i, next(a)
> gives
> 0 1
> 1 2
> 2
>
> While this:
> a = iter([1,2])
> for i in range(4):
> try:
> print i, next(a)
> except StopIteration:
> print 'StopIteration'
> gives
> 0 1
> 1 2
> 2 StopIteration
> 3 StopIteration
>
>
> On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:
>>
>> 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 "", line 1, in 
>> 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 "", line 1, in # 
>> 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 "", line 1, in # 
>> ZeroDivisionError: integer division or modulo by zero #
>>
>> Normally, you can instantiate an exception yourself, like this.
>>
>> ZeroDivisionError# Result:  #
>>
>> But guess what happens for StopIteration?
>>
>> StopIteration# Error: name 'StopIterationError' is not defined# 
>> Traceback (most recent call last):#   File "", line 1, in 
>> # 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?
>> ​
>>
> -- 
> 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+unsubscr...@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.
>


Re: [Maya-Python] StopIteration, where art thou?

2017-10-11 Thread Michael Boon
I'm on Windows. To clarify though, it's not about StopIteration being 
available (except in 2015, apparently). It's about StopIteration being 
silently caught. 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. I 
don't know what would happen in external editors.

To add to the confusion, if you catch and raise the exception, it works.
This
i = iter([0,1])
for n in range(3):
print n, next(i)
fails silently:
0 0
1 1
2

While this
i = iter([0,1])
for n in range(3):
try:
print n, next(i)
except Exception as e:
raise
shows the unhandled exception:
0 0
1 1
2# Error: 
# Traceback (most recent call last):
#   File "", line 4, in 
# StopIteration # 


On Thursday, 12 October 2017 08:09:43 UTC+11, Robert White wrote:
>
> I can see StopIteration just fine in 2018 on windows.
>
> It should live in both __builtins__ and the exceptions module. 
> Maybe some other script is messing those up?
>
> On Wednesday, October 11, 2017 at 3:23:57 PM UTC-5, Justin Israel wrote:
>>
>> Is this only in Windows? I just tested 2016, 2017, and 2018. They all 
>> have StopIteration available.
>>
>> On Tue, Oct 10, 2017 at 7:40 PM Marcus Ottosson  
>> wrote:
>>
>>> Can confirm that it is defined in 2018 as well. The above was in 2015. 
>>> How peculiar.
>>>
>>> On 10 October 2017 at 07:22, Michael Boon  wrote:
>>>
 Wow! Happens in 2016 too.
 However, StopIteration is defined, and I can catch it.

 This:
 a = iter([1,2])
 for i in range(4):
 print i, next(a)
 gives
 0 1
 1 2
 2

 While this:
 a = iter([1,2])
 for i in range(4):
 try:
 print i, next(a)
 except StopIteration:
 print 'StopIteration'
 gives
 0 1
 1 2
 2 StopIteration
 3 StopIteration


 On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:
>
> 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 "", line 1, in 
> 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 "", line 1, in # 
> 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 "", line 1, in # 
> ZeroDivisionError: integer division or modulo by zero #
>
> Normally, you can instantiate an exception yourself, like this.
>
> ZeroDivisionError# Result:  #
>
> But guess what happens for StopIteration?
>
> StopIteration# Error: name 'StopIterationError' is not defined# Traceback 
> (most recent call last):#   File "", line 1, in # 
> 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?
> ​
>
 -- 
 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+unsubscr...@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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOC6mFDTZgewPjbNNofn-8J1w55Fk7B2w5PYa4M18i9s4g%40mail.gmail.com
>>>  
>>> 

Re: [Maya-Python] StopIteration, where art thou?

2017-10-11 Thread Robert White
I can see StopIteration just fine in 2018 on windows.

It should live in both __builtins__ and the exceptions module. 
Maybe some other script is messing those up?

On Wednesday, October 11, 2017 at 3:23:57 PM UTC-5, Justin Israel wrote:
>
> Is this only in Windows? I just tested 2016, 2017, and 2018. They all have 
> StopIteration available.
>
> On Tue, Oct 10, 2017 at 7:40 PM Marcus Ottosson  > wrote:
>
>> Can confirm that it is defined in 2018 as well. The above was in 2015. 
>> How peculiar.
>>
>> On 10 October 2017 at 07:22, Michael Boon > > wrote:
>>
>>> Wow! Happens in 2016 too.
>>> However, StopIteration is defined, and I can catch it.
>>>
>>> This:
>>> a = iter([1,2])
>>> for i in range(4):
>>> print i, next(a)
>>> gives
>>> 0 1
>>> 1 2
>>> 2
>>>
>>> While this:
>>> a = iter([1,2])
>>> for i in range(4):
>>> try:
>>> print i, next(a)
>>> except StopIteration:
>>> print 'StopIteration'
>>> gives
>>> 0 1
>>> 1 2
>>> 2 StopIteration
>>> 3 StopIteration
>>>
>>>
>>> On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:

 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 "", line 1, in 
 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 "", line 1, in # 
 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 "", line 1, in # 
 ZeroDivisionError: integer division or modulo by zero #

 Normally, you can instantiate an exception yourself, like this.

 ZeroDivisionError# Result:  #

 But guess what happens for StopIteration?

 StopIteration# Error: name 'StopIterationError' is not defined# Traceback 
 (most recent call last):#   File "", line 1, in # 
 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?
 ​

>>> -- 
>>> 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+unsubscr...@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+unsubscr...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/75939951-c556-4851-8318-64fa3f2f028f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] StopIteration, where art thou?

2017-10-11 Thread Justin Israel
Is this only in Windows? I just tested 2016, 2017, and 2018. They all have
StopIteration available.

On Tue, Oct 10, 2017 at 7:40 PM Marcus Ottosson 
wrote:

> Can confirm that it is defined in 2018 as well. The above was in 2015. How
> peculiar.
>
> On 10 October 2017 at 07:22, Michael Boon  wrote:
>
>> Wow! Happens in 2016 too.
>> However, StopIteration is defined, and I can catch it.
>>
>> This:
>> a = iter([1,2])
>> for i in range(4):
>> print i, next(a)
>> gives
>> 0 1
>> 1 2
>> 2
>>
>> While this:
>> a = iter([1,2])
>> for i in range(4):
>> try:
>> print i, next(a)
>> except StopIteration:
>> print 'StopIteration'
>> gives
>> 0 1
>> 1 2
>> 2 StopIteration
>> 3 StopIteration
>>
>>
>> On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:
>>>
>>> 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 "", line 1, in 
>>> 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 "", line 1, in # 
>>> 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 "", line 1, in # ZeroDivisionError: 
>>> integer division or modulo by zero #
>>>
>>> Normally, you can instantiate an exception yourself, like this.
>>>
>>> ZeroDivisionError# Result:  #
>>>
>>> But guess what happens for StopIteration?
>>>
>>> StopIteration# Error: name 'StopIterationError' is not defined# Traceback 
>>> (most recent call last):#   File "", line 1, in # 
>>> 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?
>>> ​
>>>
>> --
>> 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+unsubscr...@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+unsubscr...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0K%3D2TuDQb7KDTqZBW410cOaM12ErrycWBhEmWaB67MFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] StopIteration, where art thou?

2017-10-10 Thread Marcus Ottosson
Can confirm that it is defined in 2018 as well. The above was in 2015. How
peculiar.

On 10 October 2017 at 07:22, Michael Boon  wrote:

> Wow! Happens in 2016 too.
> However, StopIteration is defined, and I can catch it.
>
> This:
> a = iter([1,2])
> for i in range(4):
> print i, next(a)
> gives
> 0 1
> 1 2
> 2
>
> While this:
> a = iter([1,2])
> for i in range(4):
> try:
> print i, next(a)
> except StopIteration:
> print 'StopIteration'
> gives
> 0 1
> 1 2
> 2 StopIteration
> 3 StopIteration
>
>
> On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:
>>
>> 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 "", line 1, in 
>> 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 "", line 1, in # 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 "", line 1, in # ZeroDivisionError: 
>> integer division or modulo by zero #
>>
>> Normally, you can instantiate an exception yourself, like this.
>>
>> ZeroDivisionError# Result:  #
>>
>> But guess what happens for StopIteration?
>>
>> StopIteration# Error: name 'StopIterationError' is not defined# Traceback 
>> (most recent call last):#   File "", line 1, in # 
>> 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?
>> ​
>>
> --
> 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+unsubscr...@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+unsubscr...@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.


Re: [Maya-Python] StopIteration, where art thou?

2017-10-10 Thread Michael Boon
Wow! Happens in 2016 too.
However, StopIteration is defined, and I can catch it.

This:
a = iter([1,2])
for i in range(4):
print i, next(a)
gives
0 1
1 2
2

While this:
a = iter([1,2])
for i in range(4):
try:
print i, next(a)
except StopIteration:
print 'StopIteration'
gives
0 1
1 2
2 StopIteration
3 StopIteration


On Tuesday, 10 October 2017 00:03:12 UTC+11, Marcus Ottosson wrote:
>
> 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 "", line 1, in 
> 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 "", line 1, in # 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 "", line 1, in # ZeroDivisionError: 
> integer division or modulo by zero #
>
> Normally, you can instantiate an exception yourself, like this.
>
> ZeroDivisionError# Result:  #
>
> But guess what happens for StopIteration?
>
> StopIteration# Error: name 'StopIterationError' is not defined# Traceback 
> (most recent call last):#   File "", line 1, in # 
> 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?
> ​
>

-- 
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+unsubscr...@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.


[Maya-Python] StopIteration, where art thou?

2017-10-09 Thread Marcus Ottosson
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 "", line 1, in 
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 "", line 1, in
# 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 "", line 1, in #
ZeroDivisionError: integer division or modulo by zero #

Normally, you can instantiate an exception yourself, like this.

ZeroDivisionError# Result:  #

But guess what happens for StopIteration?

StopIteration# Error: name 'StopIterationError' is not defined#
Traceback (most recent call last):#   File "", line 1,
in # 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?
​

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODh8LSkM0stnBUG03KDLDF3ObSOhe2KLcM3_5xNMuQQPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.