[Tutor] os.path.basename() issue with path slashes
Dayo Adewunmi
contactdayo at gmail.com
Sun Feb 21 01:11:47 CET 2010
Shashwat Anand wrote:
>
> <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
Arrrgh. Didn't see that forwardslash I put in there. It's fixed and
works now.
Thanks!
Dayo
More information about the Tutor
mailing list