{"action":"closed","issue":{"url":"https://api.github.com/repos/jeff1evesque/machine-learning/issues/1243","labels_url":"https://api.github.com/repos/jeff1evesque/machine-learning/issues/1243/labels{/name}","comments_url":"https://api.github.com/repos/jeff1evesque/machine-learning/issues/1243/comments","events_url":"https://api.github.com/repos/jeff1evesque/machine-learning/issues/1243/events","html_url":"https://github.com/jeff1evesque/machine-learning/issues/1243","id":56132244,"number":1243,"title":"Create superclass 'session_base.py'","user":{"login":"jeff1evesque","id":2907085,"avatar_url":"https://avatars.githubusercontent.com/u/2907085?v=3","gravatar_id":"","url":"https://api.github.com/users/jeff1evesque","html_url":"https://github.com/jeff1evesque","followers_url":"https://api.github.com/users/jeff1evesque/followers","following_url":"https://api.github.com/users/jeff1evesque/following{/other_user}","gists_url":"https://api.github.com/users/jeff1evesque/gists{/gist_id}","starred_url":"https://api.github.com/users/jeff1evesque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeff1evesque/subscriptions","organizations_url":"https://api.github.com/users/jeff1evesque/orgs","repos_url":"https://api.github.com/users/jeff1evesque/repos","events_url":"https://api.github.com/users/jeff1evesque/events{/privacy}","received_events_url":"https://api.github.com/users/jeff1evesque/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-31T17:34:42Z","updated_at":"2015-02-03T04:14:33Z","closed_at":"2015-02-03T04:14:33Z","body":"We will create a *session* superclass, `session_base.py`.  This file will be the base for `session_data_add.py` (or, its equivalent [split](https://github.com/jeff1evesque/machine-learning/issues/1244)), and `session_model_generate.py`, and will consist of the base logic initially [committed](https://github.com/jeff1evesque/machine-learning/blob/c72f760aa6118d24049cb9c9c69ce1c8da7e1ef6/package/session/session_model_generate.py) into `session_model_generate.py`.\r\n\r\n- - -\r\n\r\n## Inheritance\r\n\r\n```python\r\n#!/usr/bin/python\r\n\r\n## @example.py\r\nclass Parent(object):\r\n\r\n    def override(self):\r\n        print \"PARENT override()\"\r\n\r\n    def implicit(self):\r\n        print \"PARENT implicit()\"\r\n\r\n    def altered(self):\r\n        print \"PARENT altered()\"\r\n\r\nclass Child(Parent):\r\n\r\n    def override(self):\r\n        print \"CHILD override()\"\r\n\r\n    def altered(self):\r\n        print \"CHILD, BEFORE PARENT altered()\"\r\n        super(Child, self).altered()\r\n        print \"CHILD, AFTER PARENT altered()\"\r\n\r\ndad = Parent()\r\nson = Child()\r\n\r\ndad.implicit()\r\nson.implicit()\r\n\r\ndad.override()\r\nson.override()\r\n\r\ndad.altered()\r\nson.altered()\r\n```\r\n\r\nThen, when executed via terminal:\r\n\r\n```\r\n$ python example.py\r\nPARENT implicit()\r\nPARENT implicit()\r\nPARENT override()\r\nCHILD override()\r\nPARENT altered()\r\nCHILD, BEFORE PARENT altered()\r\nPARENT altered()\r\nCHILD, AFTER PARENT altered()\r\n```\r\n\r\n**Note:** above is taken from [Learn Python The Hard Way](http://learnpythonthehardway.org/book/ex44.html#all-three-combined).\r\n\r\n- - -\r\n## Multiple Inheritance (super)\r\n\r\n>This should seem like common sense, but then we get into trouble with a thing called multiple inheritance. Multiple inheritance is when you define a class that inherits from one or more classes, like this:\r\n\r\n>```\r\nclass SuperFun(Child, BadStuff):\r\n    pass\r\n```\r\n\r\n>This is like saying, \"Make a class named `SuperFun` that inherits from the classes `Child` and `BadStuff` at the same time.\"\r\n\r\n>In this case, whenever you have implicit actions on any `SuperFun` instance, Python has to look-up the possible function in the class hierarchy for both `Child` and `BadStuff`, but it needs to do this in a consistent order. To do this Python uses \"method resolution order\" (MRO) and an algorithm called C3 to get it straight.\r\n\r\n>Because the MRO is complex and a well-defined algorithm is used, Python can't leave it to you to get the MRO right. Instead, Python gives you the `super()` function, which handles all of this for you in the places that you need the altering type of actions as I did in `Child.altered`. With `super()` you don't have to worry about getting this right, and Python will find the right function for you.\r\n\r\n**Note:** above is taken from [Learn Python The Hard Way](http://learnpythonthehardway.org/book/ex44.html#the-reason-for-super).\r\n\r\n- - -\r\n\r\n## Method Resolution Order\r\n\r\n```python\r\n#!/usr/bin/python\r\n\r\n## @example_2.py\r\nclass First(object):\r\n  def __init__(self):\r\n    super(First, self).__init__()\r\n    print 'first'\r\n\r\nclass Second(object):\r\n  def __init__(self):\r\n    super(Second, self).__init__()\r\n    print 'second'\r\n\r\nclass Third(First, Second):\r\n  def __init__(self):\r\n    super(Third, self).__init__()\r\n    print 'third'\r\n```\r\n\r\nThen, when executed via terminal:\r\n\r\n```\r\n$ python\r\n>>> Third()\r\nsecond\r\nfirst\r\nthird\r\n```"}}