PythonPath

From XPUB & Lens-Based wiki
Revision as of 16:50, 12 June 2008 by Michael Murtaugh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Checking the extension of a file (against a list)

import os

foo = "SUNSET.JPG"
(base, ext) = os.path.splitext(foo)
ext = ext[1:] # strip first char (.)
if ext.lower() in ["jpg", "jpeg", "png", "gif"]:
	print "image!"