1

I have a code in python which looks something like this:

def Make_My_Class():
    My_Class = type("My_Class", (object, ), { 

        "__init__": Callinit, 

        "My_Funct": Call_My_Funct, 
})

def Callinit(self):
    self.value=0

def Call_My_Func(self):
    self.My_Funct=foo
...

This works fine, but I can't for the life of me figure out how to get str(My_Class), int(My_Class) or print(My_Class) to give coherent results. Any help is appreciated!

Mohd
  • 5,523
  • 7
  • 19
  • 30
nonsqu
  • 25
  • 2
  • @NicolasGervais I just followed this guide https://www.geeksforgeeks.org/create-classes-dynamically-in-python/ I am not sure what the unnecessary parts are. – nonsqu Jun 10 '20 at 15:37
  • You might want to look into the dunder methods of python classes. This article should do the trick: https://holycoders.com/python-dunder-special-methods/ – Jakob Guldberg Aaes Jun 10 '20 at 17:58

0 Answers0