[Tutor] os.path.basename() issue with path slashes
Shashwat Anand
anand.shashwat at gmail.com
Sun Feb 21 01:04:23 CET 2010
<snip>
>
> 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)
>
>
I see a small typo here.
print "<a href=\"%s/%s\"><img src=\"%s\%s\" /></a>"
%(currentdir,filename,currentdir,filename) should rather be print "<a
href=\"%s/%s\"><img src=\"%s/%s\" /></a>"
%(currentdir,filename,currentdir,filename) ..
notice the slashes "%s/%s" in href tag and "%s\%s" in img tag.
>>> filename = '1.jpg'
>>> absolutePath = os.getcwd()
>>> currentdir = os.path.basename(absolutePath)
>>> print "<a href=\"%s/%s\"><img src=\"%s/%s\" /></a>"
%(currentdir,filename,currentdir,filename)
<a href="Desktop/1.jpg"><img src="Desktop/1.jpg" /></a>
~l0nwlf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100221/07f37b18/attachment-0001.html>
More information about the Tutor
mailing list