diff --git a/advanced_topics/object_oriented_programming.ipynb b/advanced_topics/object_oriented_programming.ipynb index deca29f7e0d2aef7a45dcc7d3fa68c183ea42711..59974bc6c841755216aee1edb27bec52e95801d2 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 59aa3e99bad9496e81cd44695011871969352f0a..a180108b8a2f771d396b67b8d64a7c122607aa0a 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