1

In the following setting

from enum import Enum #class Enum2(Enum): # bla = 1 class OuterClass: class Enum1(Enum): n1 = "v1" n2 = "v2" class EnumExtended(Enum): a1 = "w1" a2 = OuterClass.Enum1 #a2 = Enum2 def __init__(self): a = OuterClass.EnumExtended for e in a: print(e, e.value) 

I get the error message "NameError: name 'OuterClass' is not defined", pointing to the line a2 = OuterClass.Enum1. Should OuterClass not be visible there? How could I otherwise reference Enum1 at that place?

And to make things even more confusing, when I run the code in a jupyter notebook, after activating and using the definition of Enum2 (which is commented out in the sample above) instead of Enum1 and then switching back to Enum1, the error is gone, but returns after a restart of the jupyter kernel. Does anyone have an explanation for this behaviour? Many thanks in advance!

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.