|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "cd666ccf-b37a-4af4-bd95-071084b91cc7", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "hello\n" |
| 14 | + ] |
| 15 | + } |
| 16 | + ], |
| 17 | + "source": [ |
| 18 | + "print('hello')" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 1, |
| 24 | + "id": "3567b9e8-3233-4767-83cf-d86f02549189", |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "class Foo:\n", |
| 29 | + " def __getattr__(self, k):\n", |
| 30 | + " print('called', k)\n", |
| 31 | + " return self.__getattribute__(k)" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": 11, |
| 37 | + "id": "359d02bb-68b6-40f1-b3f3-4e502c755645", |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "class Bar():\n", |
| 42 | + " def __init__(self):\n", |
| 43 | + " super()\n", |
| 44 | + " self.a = 1\n", |
| 45 | + " self.b = 2\n", |
| 46 | + " def asd(self):\n", |
| 47 | + " return 4" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": 12, |
| 53 | + "id": "3c4acbe5-5581-47a2-b275-bd27f3b5245f", |
| 54 | + "metadata": {}, |
| 55 | + "outputs": [], |
| 56 | + "source": [ |
| 57 | + "b=Bar()" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": 14, |
| 63 | + "id": "1ff92229-d67b-4fd4-a450-5794bb184111", |
| 64 | + "metadata": {}, |
| 65 | + "outputs": [ |
| 66 | + { |
| 67 | + "data": { |
| 68 | + "text/plain": [ |
| 69 | + "4" |
| 70 | + ] |
| 71 | + }, |
| 72 | + "execution_count": 14, |
| 73 | + "metadata": {}, |
| 74 | + "output_type": "execute_result" |
| 75 | + } |
| 76 | + ], |
| 77 | + "source": [ |
| 78 | + "b.asd()" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": 7, |
| 84 | + "id": "e72bae9e-11ec-4e2d-b8c1-10f2eab41294", |
| 85 | + "metadata": {}, |
| 86 | + "outputs": [], |
| 87 | + "source": [ |
| 88 | + "c = Foo()" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "code", |
| 93 | + "execution_count": 8, |
| 94 | + "id": "cec0e84a-a458-4043-aa8a-e43abdccb9d9", |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [ |
| 97 | + { |
| 98 | + "name": "stdout", |
| 99 | + "output_type": "stream", |
| 100 | + "text": [ |
| 101 | + "called a\n" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "ename": "AttributeError", |
| 106 | + "evalue": "'Foo' object has no attribute 'a'", |
| 107 | + "output_type": "error", |
| 108 | + "traceback": [ |
| 109 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 110 | + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", |
| 111 | + "Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43ma\u001b[49m\n", |
| 112 | + "Cell \u001b[0;32mIn[1], line 4\u001b[0m, in \u001b[0;36mFoo.__getattr__\u001b[0;34m(self, k)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getattr__\u001b[39m(\u001b[38;5;28mself\u001b[39m, k):\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcalled\u001b[39m\u001b[38;5;124m'\u001b[39m, k)\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__getattribute__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m)\u001b[49m\n", |
| 113 | + "\u001b[0;31mAttributeError\u001b[0m: 'Foo' object has no attribute 'a'" |
| 114 | + ] |
| 115 | + } |
| 116 | + ], |
| 117 | + "source": [ |
| 118 | + "c.a" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "code", |
| 123 | + "execution_count": null, |
| 124 | + "id": "6f526560-dd61-4190-aba6-2044657033d7", |
| 125 | + "metadata": {}, |
| 126 | + "outputs": [], |
| 127 | + "source": [] |
| 128 | + } |
| 129 | + ], |
| 130 | + "metadata": { |
| 131 | + "kernelspec": { |
| 132 | + "display_name": "Python 3 (ipykernel)", |
| 133 | + "language": "python", |
| 134 | + "name": "python3" |
| 135 | + }, |
| 136 | + "language_info": { |
| 137 | + "codemirror_mode": { |
| 138 | + "name": "ipython", |
| 139 | + "version": 3 |
| 140 | + }, |
| 141 | + "file_extension": ".py", |
| 142 | + "mimetype": "text/x-python", |
| 143 | + "name": "python", |
| 144 | + "nbconvert_exporter": "python", |
| 145 | + "pygments_lexer": "ipython3", |
| 146 | + "version": "3.10.9" |
| 147 | + } |
| 148 | + }, |
| 149 | + "nbformat": 4, |
| 150 | + "nbformat_minor": 5 |
| 151 | +} |
0 commit comments