problem with join
mail at timgolden.me.uk
Fri Mar 7 16:41:03 CET 2008
> i am using python on WinXP..i have a string 'folder ' that i want to
> join to a set of imagefile names to create complete qualified names so
> that i can create objects out of them
> filenms=['amber1.jpg', 'amber3.jpg', 'amy1.jpg', 'amy2.jpg']
> for x in filenms:
> now when i print the filenameslist i find that it looks like
> 'F:/brown/code/python/fgrp1\\amber3.jpg', 'F:/brown/code/python/fgrp1\
> \amy1.jpg', 'F:/brown/code/python/fgrp1\\amy2.jpg']
> is there some problem with the way i use join? why do i get \\ infront
> of the basename?
> i would prefer it like 'F:/brown/code/python/fgrp1/basename.jpg',
You've got a couple of options. Your "folder" to start
with is in the unixy form a/b/c and the .join function
doesn't do anything to change that, merely uses os.pathsep
to append the parts to each other.
You can either set your folder to be r"f:\brown\code..."
in the first case or use os.path.normpath or os.path.abspath
on the result.
More information about the Python-list