On 24/06/2021 12:44, Richard Damon wrote:
On 6/24/21 7:09 AM, Simão Afonso wrote:
On 2021-06-24 20:59:31, Steven D'Aprano wrote:
Seriously, there's a time to realise when arguments against a feature devolve down to utterly spurious claims that Python programmers are idiots who will be confused by:
from extensions use flatten mylist.flatten()
but can instantly understand:
from extensions import flatten flatten(mylist) Does this mean importing a module can modify other objects, including builtins? Should this spooky-action-at-a-distance be encouraged?
OTOH, this already happens in the stdlib with rlcompleter, I assume using monkey-patching. This is a special case for interactive use, though.
https://docs.python.org/3/library/rlcompleter.html Yes, importing a module runs the global code in that module, and that code can not only define the various things in that module but can also manipulate the contents of other modules.
This doesn't mean that spooky-action-at-a-distance is always good, but sometimes it is what is needed. You need to be aware of the power that you wield.
+1. E.g. I have a module that converts `print` to a version that prompts for continuation after each screenful of output. Very handy! Power is good, as long as it's used with discretion. Rob Cliffe