From a3e4b0b2711e4c9ad3869fa4a697fb5f04a65a6f Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Mon, 12 Feb 2018 09:41:32 +0000 Subject: [PATCH] Fix to multiple inheritance code --- advanced_topics/object_oriented_programming.ipynb | 11 +++++++++-- advanced_topics/object_oriented_programming.md | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/advanced_topics/object_oriented_programming.ipynb b/advanced_topics/object_oriented_programming.ipynb index deca29f..59974bc 100644 --- a/advanced_topics/object_oriented_programming.ipynb +++ b/advanced_topics/object_oriented_programming.ipynb @@ -1271,7 +1271,6 @@ "\n", "so.register('mylistener', capitaliseCalled)\n", "\n", - "so = StringOperator()\n", "so.do('capitalise')\n", "so.do('concat', '?')\n", "\n", @@ -1595,7 +1594,15 @@ "\n", "\n", "You can also define a method called `__new__` if you need to control the\n", - "creation stage, although this is very rarely needed. A brief explanation on\n", + "creation stage, although this is very rarely needed. One example of where you\n", + "might need to implement the `__new__` method is if you wish to create a\n", + "[subclass of a\n", + "`numpy.array`](https://docs.scipy.org/doc/numpy-1.14.0/user/basics.subclassing.html)\n", + "(although you might alternatively want to think about redefining your problem\n", + "so that this is not necessary).\n", + "\n", + "\n", + "A brief explanation on\n", "the difference between `__new__` and `__init__` can be found\n", "[here](https://www.reddit.com/r/learnpython/comments/2s3pms/what_is_the_difference_between_init_and_new/cnm186z/),\n", "and you may also wish to take a look at the [official Python\n", diff --git a/advanced_topics/object_oriented_programming.md b/advanced_topics/object_oriented_programming.md index 59aa3e9..a180108 100644 --- a/advanced_topics/object_oriented_programming.md +++ b/advanced_topics/object_oriented_programming.md @@ -1018,7 +1018,6 @@ def capitaliseCalled(result): so.register('mylistener', capitaliseCalled) -so = StringOperator() so.do('capitalise') so.do('concat', '?') @@ -1298,7 +1297,15 @@ created. You can also define a method called `__new__` if you need to control the -creation stage, although this is very rarely needed. A brief explanation on +creation stage, although this is very rarely needed. One example of where you +might need to implement the `__new__` method is if you wish to create a +[subclass of a +`numpy.array`](https://docs.scipy.org/doc/numpy-1.14.0/user/basics.subclassing.html) +(although you might alternatively want to think about redefining your problem +so that this is not necessary). + + +A brief explanation on the difference between `__new__` and `__init__` can be found [here](https://www.reddit.com/r/learnpython/comments/2s3pms/what_is_the_difference_between_init_and_new/cnm186z/), and you may also wish to take a look at the [official Python -- GitLab