0

I am trying to do something that looks something like this:

class Foo:
    def __init__(self, x, y):
        print(x + y)

a = Foo(10,20)
b = a.CLASSTYPE(20,30)

(Note: I know that there is nothing such as CLASSTYPE)

Is something like this possible? And if it is, how could I implement it in python. Anything would be greatly appreciated, thanks!

Yawn
  • 71
  • 7

1 Answers1

1

You can simply get a reference the type of a, then call that:

b = type(a)(20, 30)

There's also a.__class__, but you should generally avoid using so-called dunder names (name beginning and ending with a double underscore) directly.

chepner
  • 497,756
  • 71
  • 530
  • 681