0

I have the class sprite with the inner class type.

class sprite:
    class type:
        ThisValue = 10
        OtherValue = 22

    def __init__(self, type = sprite.type.ThisValue):
        self.type = type

When I try this, it says that the name sprite is not defined; the error throws on the def __init__() line. How can I access ThisValue in the function definition? Is there a better way to write the type class?

Tanner H.
  • 304
  • 1
  • 13

1 Answers1

1

You need just

def __init__(self, type = type.ThisValue):
kvorobiev
  • 5,012
  • 4
  • 29
  • 35
  • Thanks, I'm dumb for not thinking about that haha – Tanner H. Sep 26 '18 at 05:52
  • @Tanner H. Please note, that same names for class and parameter is generally bad idea. Better to rename `class type` to something like `class type_cls` or rename method argument. – kvorobiev Sep 26 '18 at 05:57