How to detect the presence of a html file

Kent Johnson kent at kentsjohnson.com
Sat Dec 10 02:40:32 CET 2005


Peter Hansen wrote:
> 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...

I often copy paths from Windows Explorer and paste them into Python 
strings. (I hate typing paths!) Raw strings are much handier in that 
case - no editing required on the path.

Kent



More information about the Python-list mailing list