Skip to content

Instantly share code, notes, and snippets.

@drorata
Created September 16, 2022 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drorata/500259eb914fdbf79586805c121c892e to your computer and use it in GitHub Desktop.
Save drorata/500259eb914fdbf79586805c121c892e to your computer and use it in GitHub Desktop.
Minimal example using abstract class
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