Search the web
Sign In
New User? Sign Up
perl-python
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Python Doc Problem Example: os.path.split()   Message List  
Reply | Forward Message #105 of 127 |
Python Doc Problem Example: os.path.split()

Xah Lee, 20050918

Quote from: http://www.python.org/doc/2.4.1/lib/module-os.path.html

split(path)
Split the pathname path into a pair, (head, tail) where tail is the
last pathname component and head is everything leading up to that. The
tail part will never contain a slash; if path ends in a slash, tail
will be empty. If there is no slash in path, head will be empty. If
path is empty, both head and tail are empty. Trailing slashes are
stripped from head unless it is the root (one or more slashes only). In
nearly all cases, join(head, tail) equals path (the only exception
being when there were multiple slashes separating head from tail).

This confusive verbiage is a result of the author's pretention in a
austere style and his failure to think clearly before writing.

Suggested rewrite:

split(path)
returns a pair (dirname,filename), where dirname is the part of
path up to the last slash, and filename is the rest of the string after
the last slash.

Exceptional cases are:
• if path is a single slash (or repeated), then path == dirname and
filename is empty.
• If the “last” slash is repeated, they are treated as one single
slash.
-----------
This post is archived at:
http://xahlee.org/perl-python/python_doc_os_path_split.html








Sun Sep 18, 2005 11:38 am

p0lyglut
Offline Offline
Send Email Send Email

Forward
Message #105 of 127 |
Expand Messages Author Sort by Date

Python Doc Problem Example: os.path.split() Xah Lee, 20050918 Quote from: http://www.python.org/doc/2.4.1/lib/module-os.path.html split(path) Split the...
xah lee
p0lyglut
Offline Send Email
Sep 18, 2005
11:44 am

... Umm nearly - but the exceptions should be as follows: * If the last slash is repeated, and it is not the first set of slashes, it treated as single slash. ...
danny staple
orionrobots@...
Send Email
Sep 19, 2005
8:06 am

Addendum to the Python doc problem at http://www.python.org/doc/2.4.1/lib/module-os.path.html I was working on a program where i needed to split a path into...
xah lee
p0lyglut
Offline Send Email
Sep 20, 2005
5:41 pm
Advanced

Copyright 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help