[Tutor] os.path.basename() issue with path slashes

Dayo Adewunmi contactdayo at gmail.com
Sun Feb 21 00:49:19 CET 2010

Hi all,

This script I'm working on, should take all the image files in the current directory
and generate an HTML thumbnails.

import os
import urllib

# Generate thumbnail gallery
def genThumbs():
    # Get current directory name
    absolutePath = os.getcwd()
    urlprefix = "http://kili.org/~dayo"
    currentdir = os.path.basename(absolutePath)

    for dirname, subdirname, filenames in os.walk(absolutePath):
        for filename in filenames:
            print "<a href=\"%s/%s\"><img src=\"%s\%s\" /></a>" %(currentdir,filename,currentdir,filename)

# Generate thumbnail gallery

However, this is the type of output I get:

<a href="http://kili.org/~dayo/thumbs/00838_drops_1024x768.jpg"><img src="http://kili.org/~dayo\thumbs\00838_drops_1024x768.jpg" /></a>

See how in the url in the src attribute of the img tag the slashes after "~dayo"
are somehow turned into backslashes, instead of forwardslashes. How come?

Best regards


More information about the Tutor mailing list