PythonPath: Difference between revisions

From XPUB & Lens-Based wiki
(New page: == Checking the extension of a file (against a list) == <source lang="python"> import os foo = "SUNSET.JPG" (base, ext) = os.path.splitext(foo) ext = ext[1:] # strip first char (.) if e...)
 
No edit summary
 
Line 1: Line 1:
== Checking the extension of a file (against a list) ==
== Checking the extension of a file (against a list) ==
<source lang="python">
<source lang="python">

Latest revision as of 17:50, 12 June 2008

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!"