[Shane Holloway] > When I > write classes, I tend to put the public methods at the top. Utility > methods used by those entry points are placed toward the bottom. In > this way, I read the context of what I'm doing first, and then the > details of the internal methods as I need to understand them. > > Granted I could achieve this effect with:: > > class Before: > def readIt(self, filename): > def readIt(): > withFile(filename, doReading) > > def doReading(aFile): > self.readPartA(aFile) > self.readPartB(aFile) > self.readPartC(aFile) > > return readIt() > > Which is fine with me, but the *intent* is more obfuscated than what the > block construct offers. And I don't think my crew would appreciate if I > did this very often. ;)
I typically solve that by making doReading() a method: class Before: def readit(self, filename): withFile(filename, self._doReading) def _doReading(self, aFile): self.readPartA(aFile) self.readPartB(aFile) self.readPartC(aFile) Perhaps not as Pure, but certainly Practical. :-) And you could even use __doReading to make it absolutely clear that doReading is a local artefact, if you care about such things. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com