Let’s consider this abstract base class and its subclass, implementing an abstract method:
class MyBaseClass(ABC): @abstractmethod def do_it(self): pass class MySubClass(MyBaseClass): def do_it(self): print("I'm doing it now.")
Let’s say I will only use MySubClass once and I don’t want to declare it as a class, but rather create it ad-hoc, inline, as an anonymous class. Is it possible in Python? In Java it would work like this:
MyBaseClass anon = new MyBaseClass() { @Override public void do_it() { System.out.println("I'm doing it now."); } }; anon.do_it();
submitted by /u/pachura3
[link] [comments]
r/learnpython Let’s consider this abstract base class and its subclass, implementing an abstract method: class MyBaseClass(ABC): @abstractmethod def do_it(self): pass class MySubClass(MyBaseClass): def do_it(self): print(“I’m doing it now.”) Let’s say I will only use MySubClass once and I don’t want to declare it as a class, but rather create it ad-hoc, inline, as an anonymous class. Is it possible in Python? In Java it would work like this: MyBaseClass anon = new MyBaseClass() { @Override public void do_it() { System.out.println(“I’m doing it now.”); } }; anon.do_it(); submitted by /u/pachura3 [link] [comments]
Let’s consider this abstract base class and its subclass, implementing an abstract method:
class MyBaseClass(ABC): @abstractmethod def do_it(self): pass class MySubClass(MyBaseClass): def do_it(self): print("I'm doing it now.")
Let’s say I will only use MySubClass once and I don’t want to declare it as a class, but rather create it ad-hoc, inline, as an anonymous class. Is it possible in Python? In Java it would work like this:
MyBaseClass anon = new MyBaseClass() { @Override public void do_it() { System.out.println("I'm doing it now."); } }; anon.do_it();
submitted by /u/pachura3
[link] [comments]