Skip to content

Instantly share code, notes, and snippets.

@mylons
Created November 9, 2011 22:24
Show Gist options
  • Save mylons/1353320 to your computer and use it in GitHub Desktop.
Save mylons/1353320 to your computer and use it in GitHub Desktop.
super split!
import os
def super_split(absolute_path):
fdir, fname = os.path.split(absolute_path)
tokens = fname.split('.')
ext = tokens[-1]
fname_no_ext = '.'.join( [ x for x in tokens[:len(tokens)-1] ])
return fdir, fname_no_ext, ext
@brentp
Copy link

brentp commented Nov 28, 2011

(returning the favor)

check out os.path.splitext or

fname_no_ext, ext = fname.rsplit(".", 1)

@mylons
Copy link
Author

mylons commented Nov 29, 2011

@brentp thank you, sir. I've never used rsplit, and will have to add it to the lexicon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment