[Chicago] Reading From a Directory

JongMan Koo jongman at gmail.com
Tue May 10 07:49:29 CEST 2011


A few things to clarify...


> C has libraries for opening and reading directories.


No, it doesn't. The C language standard doesn't define any standard way to
work with directories. To access directories C programs have to use platform
dependent code: In POSIX you must use opendir, readdir and company, and in
Windows you must use FindFirstFile and company.


> Python does not.


Yes, it does. All the methods mentioned above (os.listdir and glob.glob) are
included in Python's standard library.


> Most languages just treat directories as a special sort of file, and just
> don't get all that worked up.


I don't understand why you are treating standard libraries as something not
inherent with the language. All the directory access functionality in all
the languages come from some kind of standard library or some code in the
runtime. So the only difference between those "most languages" and Python
would be whether they are "included" by default (or bound to the language
syntax, which sounds like an worse option to me), or you have to elect for
it. Doesn't look like a big difference to me.

--JongMan

2011/5/9 Clyde Forrester <clydeforrester at gmail.com>

> Martin Maney wrote:
>
>> On Mon, May 09, 2011 at 10:08:11PM -0500, Clyde Forrester wrote:
>>
>>> I'm making the tough mental shift from
>>>
>>> It's so trivially easy that everyone EXCEPT Python has the ability
>>> to open, read, and close a directory. What could be easier?
>>>
>>> to
>>>
>>> Just because you CAN do it that way, doesn't mean you SHOULD. Or,
>>> for that matter, that it's the most direct or simplest way.
>>>
>>
>> Well, you CAN do it that way... in, say, Perl.  In C, C++, Python, and
>> a horde of other languages, it's not a hardwired feature of the
>> language, but an external function.  Modules (and Packages) are
>> Python's way of managing external code.  In fact, despite the different
>> appearances, ALL these languages "pass the buck" to the OS in the end:
>> they only differ in how they present the slot for receiving the buck. And
>> a bazillion other things are like this...
>>
> I don't think that you understand my objection.



> I have no objection to modules, packages and libraries.



>
>
>>  Yeah, yeah. I'll get over it.
>>>
>>
>> I hope you do, because Python very generally prefers to package things
>> into modules rather than making them builtins or keywords or whatever. You
>> don't half know what Python is if you haven't gotten to know the
>> standard library.  Not know it all by heart - I doubt anyone does.  But
>> knowing that it's there, and how to find out what's in there that you
>> don't already know about is not important, it's essential.
>>
>>  Again, you've misread my intent. I've gotten used to extensive modules
> and libraries in languages like Java. That's not my complaint. That's not
> what I'm getting used to.



> With files, much of the time one just wants the whole thing also. But not
> always. If I'm doing a compare and it fails on the first block, then boom,
> I'm done, it failed, no need to go on. But with directories, there isn't a
> situation where I don't want to examine the whole thing. That was a big
> blindspot in my mind, and that's what I'm getting used to.
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20110510/4f7574a2/attachment.html>


More information about the Chicago mailing list