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!

ctenar
  • 718
  • 5
  • 24
  • Does this answer your question: https://stackoverflow.com/questions/42185472/python-reference-inner-class-from-other-inner-class – Mark Jun 06 '20 at 19:58
  • Seems so, thank you! – ctenar Jun 06 '20 at 20:05
  • Does this answer your question? [Python - reference inner class from other inner class](https://stackoverflow.com/questions/42185472/python-reference-inner-class-from-other-inner-class) – wwii Jun 06 '20 at 22:01

0 Answers0