How to detect the presence of a html file

Peter Hansen peter at engcorp.com
Fri Dec 9 15:17:20 EST 2005


Kent Johnson wrote:
> The simplest fix is to use raw strings for all your Windows path needs:
> os.path.isfile(r'c:\bookmarks.html')
> os.path.isfile(r'c:\wumpus.c')

Simpler still is almost always to use forward slashes instead:

os.path.isfile('c:/bookmarks.html')
os.path.isfile('c:/wumpus.c')

The only time this doesn't really work is when you pass the path to the 
Windows "shell".  Or when you naively compare paths without using 
something like normpath() on them first...

-Peter




More information about the Python-list mailing list