Skip to content

Instantly share code, notes, and snippets.

@p2004a
Last active August 29, 2015 14:17
Show Gist options
  • Save p2004a/7efe2fea338704f13ed9 to your computer and use it in GitHub Desktop.
Save p2004a/7efe2fea338704f13ed9 to your computer and use it in GitHub Desktop.
Python tutorial for programmers
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:f03f78294be62c5aaa0255e8ce1c4f9938a6e8288378563d1432ef0d28b7c7d3"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Python cz\u0119\u015b\u0107 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_Under construction_"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Dziedziczenie wielobazowe i MRO (Method Resolution Order)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://www.python.org/download/releases/2.3/mro/ (Dokumentacja pythona odnosi si\u0119 do tego dokumenty w kwestii MRO)"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Metaklasy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Dobry blogpost: http://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/\n",
"\n",
"Wpis z dokumentacji: https://docs.python.org/3/reference/datamodel.html#customizing-class-creation"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class F:\n",
" def __init__(self):\n",
" print(\"init begin\")\n",
" self.n = 5\n",
" print(\"init end\")\n",
" \n",
" def __getattr__(self, what):\n",
" print(\"getattr: \" + what)\n",
" return super().__getattr__(what)\n",
" \n",
" def __setattr__(self, what, value):\n",
" print(\"setattr: \" + what + \" = \" + str(value))\n",
" super().__setattr__(what, value)\n",
"\n",
" \n",
"a = F()\n",
"try:\n",
" a.asdasd\n",
"except:\n",
" print(\"OK\")\n",
"\n",
"a.asd = 3\n",
"print(a.asd)\n",
"\n",
"a.n\n",
"a.n = 10"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"init begin\n",
"setattr: n = 5\n",
"init end\n",
"getattr: asdasd\n",
"OK\n",
"setattr: asd = 3\n",
"3\n",
"setattr: n = 10\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment