dimanche 16 mai 2021

Use class constants in definition of nested class in python

class Parent:
  separator = "|"
  
  class DataContainer:
    def __init__(self, data):
      self.data = data.split(**separator**)

In the following snippet, is there a way to get the value of Parent.separator into the subclass?

As a side note: The sub-class is a data structure used only in the Parent class. Do you find this as a good design choice? Or should it be a normal class?

Aucun commentaire:

Enregistrer un commentaire