Skip to content

Instantly share code, notes, and snippets.

@armsp
Last active December 6, 2018 16:34
Show Gist options
  • Save armsp/7f4b733f54c6d85ec8d12e8af4323528 to your computer and use it in GitHub Desktop.
Save armsp/7f4b733f54c6d85ec8d12e8af4323528 to your computer and use it in GitHub Desktop.
class fish:
def __init__(self,name):
self.name = name
self.skeleton = "bones"
def swims(self):
print(self.name, "swims")
def eyes(self):
print(self.name, "has eyelids")
class salmon(fish):
pass
f = salmon("sal")
print(f.name, f.skeleton)
f.swims()
f.eyes()
class trout(fish):
def has_fins(self):
print(self.name, "has fins")
t = trout('bob the trout')
print(t.name, t.skeleton)
t.swims()
t.eyes()
t.has_fins()
class eel(fish):
def __init__(self,name):
self.name = name
self.skeleton = "cartilage"
def swims(self):
print(self.name, "It can swim backwards too")
def shock(self):
print(self.name, "can shock you too")
e = eel('tom')
print(e.name, e.skeleton)
e.swims()
e.eyes()
e.shock()
class sum:
def __init__(self,a,b):
self.op1 = a
self.op2 = b
def sumit(self):
print("inside sum sumit")
print(self.op1+self.op2)
class prod:
def __init__(self,a,b):
self.mul1 = a
self.mul2 = b
def mulit(self):
print("inside prod mulit")
print(self.mul1*self.mul2)
class operation(sum,prod):
def __init__(self,a,b):
self.opd1 = a
self.opd2 = b
def perform(self):
sum_o = sum(self.opd1, self.opd2)
prod_o = prod(self.opd1, self.opd2)
print(sum_o.sumit())
print(prod_o.mulit())
o = operation(2,3)
o.perform()
# Why is None getting printed ?
class simple_op(sum,prod):#Only the attributes of sum become the attributes of simple_op, Why? Attributes of prod must also become attributes of simple_op
pass
s_o = simple_op(7,8)
print(s_o.op1, s_o.op2)
print(s_o.mul1, s_o.mul2)
s_o.mulit()
s_o.sumit()
# https://www.digitalocean.com/community/tutorials/how-to-use-logging-in-python-3
# https://www.digitalocean.com/community/tutorials/how-to-use-the-python-debugger
# https://github.com/faif/python-patterns
# https://python-3-patterns-idioms-test.readthedocs.io/en/latest/PatternConcept.html
# https://github.com/faif/python-patterns/blob/master/README.md
# http://ivory.idyll.org/articles/advanced-swc/
# https://web.archive.org/web/20120118192448/http://jaynes.colorado.edu/PythonIdioms.html
# https://legacy.python.org/workshops/1997-10/proceedings/savikko.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment