Michael Foord wrote: > There was code posted that used the (almost entirely sane) pattern : > > new_filename = os.path.splitext(old_filename)[1] + '.bak' > > That was broken but is now fixed. It follows the entirely natural > assumption that filename without an extension would not have the > filename put in the extension half of the tuple.
Well, I'd argue the sanity of it, but you're right - it was posted. > The documentation (not the docstring) actually says : > > splitext( path) > > Split the pathname path into a pair (root, ext) such that root + > ext == path, and ext is empty or begins with a period and contains at > most one period. > > Even the docstring only states that either part may be empty, hardly > documenting what is clearly a misfeature. splitext(p) Split the extension from a pathname. Extension is everything from the last dot to the end. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Return (root, ext), either part may be empty. That's pretty explicit. Tim Delaney _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com