This post originated from an RSS feed registered with Python Buzz
by Ian Bicking.
Original Post: path module
Feed Title: Ian Bicking
Feed URL: http://www.ianbicking.org/feeds/atom.xml
Feed Description: Thoughts on Python and Programming.
I've been using Jason Jorendorff's path module lately in a couple
command-line scripts. A while ago I stopped writing many scripts in
shell, since I always found it hard to grow the scripts, and the
quoting always causes problems. How many shell scripts can deal with
filenames with spaces in them? Shell scripting is a crappy language.
I always thought Tcl would make a good shell -- both simpler and more
reliable than shell, but just as string-oriented. But it never seemed
to happen... so it goes.
Anyway, when writing command-line programs you do lots of file
operations, and typically use os.path a lot. os.path is a
pain to use -- too much os.path.join(os.path.dirname(...)) and
the like. This makes Python rather painful to use.
Despite wanting a path module for a long time, I keep forgetting to
use the one I have (standard or no). After using it some, I find it
very pleasant. Besides avoiding os.path, I get nice functions
like text() and write_text() which read and write text to the
file in a single chunk, no open() required. And I'm sure there's
more good stuff in there that I haven't assimilated yet either.
There's an outstanding (pre) PEP, and a second discussion on
comp.lang.python surrounding a path module. Personally Jason's
module fits me well, and I think it's worth the time to learn even if
you've become accustomed (as I have) to os.path.
(And I like the use of / for os.path.join -- purists say that
it's not division, but I say who cares; % substitution isn't
modulo either)