0

My problem is quite similar to this one: Access outer class from inner class in python

I am using tkinter and need a 2|3-level tree and plan to make my code structure similar to the Ui => nested class.

class Item():
    ...
class BasicItem():
    ...

class Transports(Item):
    class Bikes(Item):
        class Tears(BasicItem):
class Feelings(Item):
    class Tears(BasicItem):

Python complains because the classes can't be reached from the nested classes. What am I doing wrong? According to the above link, nested are no the way to go. Am I to understand that I should flatten my code and use a TransportsBikesTears class name? Thank you.

edit: A minimal example works. I will try to rewrite from a working file. edit2: This example nested in a mother-class fail.

Community
  • 1
  • 1
funkygoby
  • 13
  • 6

1 Answers1

0

I learned that classes are nor supported in Python but works "sometimes" as an artifact. I can't find the link but since people keeps using it, they are considering removing this artifact.

My mistake came from trying this in a function and that comforted me with this practice. One you put my example above in a mother-class, it won't work and the nested class won't be able to inherit from Item.

Lesson learned. No more nested classes in Python.

funkygoby
  • 13
  • 6