Encapsulation in Python

Rick Johnson rantingrickjohnson at gmail.com
Sat Mar 12 22:36:03 EST 2016


On Saturday, March 12, 2016 at 3:10:49 PM UTC-6, Chris Angelico wrote:
> Also, if currentModule.py is pulling foo from modX, then modZ.py is an
> implementation detail. You don't necessarily want to go straight
> there; tracing the chain is more likely to be the correct behaviour.
> Suppose modX.py actually looks like this:
> 
> if 'posix' in some_magic:
>     import posixY as modY
> elif 'nt' in some_magic:
>     import ntY as modY
> else:
>     raise ImportError

Ha, well, along with my example, this is another good
example of a very bad design ;-). It's a terrible sin to
import a symbol through multiple modules, but to import a
symbol through multiple modules *AND* redefine it along the
way, well, that should be punishable by the fatal exception.
No judge, no jury. Just swift, and absolute, justice. :-)




More information about the Python-list mailing list