Created
September 16, 2022 10:49
-
-
Save drorata/500259eb914fdbf79586805c121c892e to your computer and use it in GitHub Desktop.
Minimal example using abstract class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABC, abstractmethod | |
class EcgDataBase(ABC): | |
@abstractmethod | |
def __init__(self): | |
pass | |
@abstractmethod | |
def __iter__(self): | |
pass | |
class DataExample(EcgDataBase): | |
def __init__(self): | |
self.data = "foo" | |
def __iter__(self): | |
yield from [1,2,3,4] | |
try: | |
edb = EcgDataBase() | |
except TypeError: | |
print( | |
"This cannot work, because it is meaningless to instantiate an abstarct class" | |
) | |
dataExample = DataExample() | |
print(dataExample.data) | |
for i in dataExample: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment