Last active
August 29, 2015 14:17
-
-
Save p2004a/7efe2fea338704f13ed9 to your computer and use it in GitHub Desktop.
Python tutorial for programmers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment