[Python-Dev] stat module in C -- what to do with stat.py?

Stephen J. Turnbull stephen at xemacs.org
Sat Jun 22 02:01:53 CEST 2013


Gustavo Carneiro writes:

 > On Fri, Jun 21, 2013 at 8:20 PM, Steven D'Aprano <steve at pearwood.info> wrote:

 >> -1 Reading the Python source code is a very good way for beginner
 >> programmers to learn about things like this.

 > On the other hand, it is counter-productive to learn about code
 > that is conceptually _wrong_.

It's hardly _conceptually_ wrong when it's simply a pure-Python
version that reflects *exactly* the implementation used by many OSes
written in C.  It's purely a quality of implementation issue in that
it fails to observe the DRY principle and is non-portable.  But if you
look at <sys/stat.h> on Mac OS X or Linux, you'll see that the visible
definitions are protected by a thicket of #ifdefs, and the actual
definitions may be drawn from other files #include'd there, and not
using the definitions visible in <sys/stat.h> at all.  Ie, on those
systems the OS implementation possesses exactly the same structure
that CPython would have with a stat.py + _stat module implementation.

If the presence of the _stat module is documented and the rationale
briefly explained in stat.py, I suppose you have the best of both
worlds for the novice programmer (at the expense of a test for the
presence of _stat at import time).


More information about the Python-Dev mailing list