Skip to content

Instantly share code, notes, and snippets.

@suranands
Created December 24, 2014 16:43
Show Gist options
  • Save suranands/e60972af728c363079f5 to your computer and use it in GitHub Desktop.
Save suranands/e60972af728c363079f5 to your computer and use it in GitHub Desktop.
OOPy_Practice
{
"metadata": {
"name": "",
"signature": "sha256:f6e04d58f2a638268531d2372b0b09562304debfc7fdfd2e11b9b2b94ccc37e2"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#OOPy_Practice_24d14\n",
"\n",
"##I am very very new to programming and more so to Python. \n",
"\n",
"But through some of the motivational videos on youtube which can be found in playlist, I already love \n",
"\n",
"* the 2 most powerful features of Python programming\n",
" * IPython (IPy)\n",
" * IPython Notebook (IPyNB)\n",
"* and 2 amazing features associated with Python programming\n",
" * Git Gist [Link](https://gist.github.com/)\n",
" * IPyNB Viewer [Link](http://nbviewer.ipython.org/)\n",
"\n",
"\n",
"Not sure if everybody does the same thing. But here is what I feel a great way to learn this all. As long as I am not getting into scripting, I mean I'm coding just on the interactive Py/IPy sessions, this is the best way to keep track of what I have been doing all the way down. So began my practice and this IPyNB file for my own reference!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***Notice the Input and Output numbers here? They are jumbled because I inserted cells after I went ahead coding for a while. Isn't this cool?***"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pwd"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 22,
"text": [
"u'/wind/A-Life/Programming 10Aug2014/Python Aug 2013/python_9oct14/OOPy/my_work20d14'"
]
}
],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class exampleClass:\n",
" eyes = \"blue\"\n",
" age = 22\n",
" def thisMethod(self):\n",
" return 'hey this method worked'"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleClass"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"__main__.exampleClass"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleObject = exampleClass()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleObject.eyes"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"'blue'"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleObject.age"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
"22"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleObject.thisMethod()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"'hey this method worked'"
]
}
],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleObject.thisMethod(abs)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "thisMethod() takes exactly 1 argument (2 given)",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-8-4bbbaa0ed85f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mexampleObject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mthisMethod\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mabs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m: thisMethod() takes exactly 1 argument (2 given)"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"exampleObject.thisMethod()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
"'hey this method worked'"
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class className:\n",
" def createName(self,name):\n",
" self.name = name\n",
" def displayName(self):\n",
" resturn self.name"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-10-b679e5c2a88d>, line 5)",
"output_type": "pyerr",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-10-b679e5c2a88d>\"\u001b[1;36m, line \u001b[1;32m5\u001b[0m\n\u001b[1;33m resturn self.name\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class className:\n",
" def createName(self,name):\n",
" self.name = name\n",
" def displayName(self):\n",
" return self.name\n",
" def saying(self):\n",
" print \"hello %s\" % self.name"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"className"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
"__main__.className"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"first = className()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"second = className()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"first.createName('abs')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"first.displayName()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 16,
"text": [
"'abs'"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"second.createName('ABS')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"second.displayName"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 18,
"text": [
"<bound method className.displayName of <__main__.className instance at 0x7f85d6592368>>"
]
}
],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"second.displayName()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 19,
"text": [
"'ABS'"
]
}
],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"first.saying()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"hello abs\n"
]
}
],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"second.saying()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"hello ABS\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### So far, I had been following the youtube [playlist](https://www.youtube.com/watch?v=M1BAlDufqao&index=33&list=PLEA1FEF17E1E5C0DA) by \"The New Boston's Bucky\". From here, I am going to check out the saved book in this same folder, titled \"Python 3 Object **Oriented Programming\"**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* This book has a dedicated first chapter introducing the importance of designing before getting to code, particularly in UML language. I am not sure what this is yet, but I would love to know this too as soon as I can."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment