[Tutor] Automated Breadcrumb -- help for a PHP user

Chris Heisel chris at heisel.org
Wed Nov 26 14:55:59 EST 2003


I wanted to thank everyone for their help, I've successfully finished my 
first (non-hello-world) Python program.

I'd love any feedback that you all have about ways I might improve it 
and make it more Python-like...

Thanks again,

Chris

<CODE>
def nameHandler(name):
	if 'index.html' == name:
		name = ''
		return name
	elif name.endswith('.html'):
		name = 'Content'
		return name
	else:
		name = name.capitalize()
		return name

def valueChecker(value):
	if '' == value:
		pass
	else:
		return value

def breadMaker(url, basedir, basedir_name, glue):
     path_parts = url.split('/')
	#path_parts has an empty first item we need to fix it here

     href = basedir
     output = '<p class="trail"><a href="%s">%s</a> %s ' % (basedir, 
basedir_name, glue)

     for value in path_parts:
     	name = nameHandler(value)
     	if '' == name:
     		continue #if its a blank string try again
     	
     	if value.endswith('.html'):
     		href = href+value
     	else:
         	href = href+value+'/'
     	
     	if 'Content' == name:
     	   	output += '<a href="%s">%s</a>' % (href, name)
     	else:
     	   	output += '<a href="%s">%s</a> %s ' % (href, name, glue)

     output = output+'</p>'
     return output
		

print "Content-type: text/plain\n\n"
path = os.environ['DOCUMENT_URI']

basedir = '/'
basedir_name = 'AJC Sports Plus'

trail = breadMaker(path, basedir, basedir_name, '>')
print trail




More information about the Tutor mailing list