Another newbie question

Paul Rubin http
Sun Dec 11 01:16:04 EST 2005


Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> The fact that sys is a module and not a class is a red herring. If the
> "Law" of Demeter makes sense for classes, it makes just as much sense for
> modules as well -- it is about reducing coupling between pieces of code,
> not something specific to classes. 

I don't see that.  If a source line refers to some module you can get
instantly to the module's code.  But you can't tell where any given
class instance comes from.  That's one of the usual criticisms of OOP,
that the flow of control is obscured compared with pure procedural
programming.

> One dot good, two dots bad.

Easy to fix.  Instead of sys.stdout.write(...) say

  from sys import stdout

from then on you can use stdout.write(...) instead of sys.stdout.write.



More information about the Python-list mailing list