[Chicago] Reading From a Directory

Dan Krol orblivion at gmail.com
Tue May 10 01:36:55 CEST 2011


You can get the list of files thusly:

http://docs.python.org/library/os.html#os.listdir

<http://docs.python.org/library/os.html#os.listdir>And you can open each
file for their contents from there. Will that do?

On Mon, May 9, 2011 at 6:32 PM, Clyde Forrester <clydeforrester at gmail.com>wrote:

> What I want to do is open a directory and read file names from it.
>
> The standard answer I get by Googling seems to be:
> No you don't. Are you mad? Why would you want to do that? Clearly you want
> to do something else. It's a scripting language and you have no business
> "programming" in it. Why don't you just pass the buck to a shell (os.popen)
> and handle it that way? Or use a magic module glob.glob) to get a complete
> list, or something.
>
> Perl and Ruby have directory classes with open, read, and close methods.
> Why doesn't Python?
>
> Now it does occur to me that any time I want to read from a directory, I
> want all the files. Even if I'm using a wild card, I want to apply it to all
> the files in the directory, not just the first one or two. But somehow
> calling out to a shell, or invoking a module seems as "easy" as hiring a
> subcontractor to tie my shoes. I don't things have to get that complicated.
>
> c4
> _______________________________________________
> 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/20110509/1169a513/attachment.html>


More information about the Chicago mailing list