<div class="gmail_quote">On Mon, May 9, 2011 at 23:35, Clyde Forrester <span dir="ltr">&lt;<a href="mailto:clydeforrester@gmail.com">clydeforrester@gmail.com</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

I don&#39;t think that you understand my objection. C has libraries for opening and reading directories. Python does not.</blockquote><div><br></div><div>If you wanted to, you could use ctypes and access whatever POSIX shared libraries you want and you could write the exact same code in Python as you could in C.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> I have no objection to modules, packages and libraries. What I&#39;m objecting to is the notion that Python can&#39;t inherently read directories. What goes on in the module? Is it secret code? Is it in another language?</blockquote>
<div><br></div><div>The os module is 10,176 lines of C (in Modules/posixmodule.c) and 832 lines of Python (in Lib/os.py), joined together to provide a fairly thin layer over the platform libraries (POSIX, Windows API, etc). os.listdir in particular boils down to around 75 lines of C, most of which is error checking, argument conversion boilerplate (converting from a Python string to a char* directory name), etc. Stripping all of that out, you get an opendir call, then we loop readdir calls around that result.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Is Python&#39;s standard solution to anything tricky to write a module in another language and then invoke the module from Python? Most languages just treat directories as a special sort of file, and just don&#39;t get all that worked up.</blockquote>
<div><br></div><div>Like most high level languages, stuff like listing a directory is simplified and abstracted away. You end up with a one line call &quot;os.listdir(dir)&quot; rather than everyone re-inventing the wheel with their own opendir/readdir loop. Directories aren&#39;t really treated as anything other than a string name - you pass a directory name to various functions and they operate on the directory for you.</div>
</div>