os.path.dirname adds unremoveable spaces?
Jason
asldfkjasldfj at asldfkjasldkfjasdf.com
Sat Apr 17 14:11:36 EDT 2004
That's some great info, thanks. I never actually figured out what was
adding the spaces, so I appreciate your explanation. This is only my third
day of Python.
>
> Just to add a couple of notes... You probably shouldn't be using the
> strip() function at all. What if the directory or filename does have
> leading or trailing spaces? Presumably you would want to keep those
> when constructing a full path.
>
> Also, you did figure out that it was the print statement adding the
> spaces, right? Try this test:
>
> print 'one', '/', 'two'
>
> and compare the results with this:
>
> print '%s/%s' %( 'one', 'two' )
>
> In the second example, you're giving a single argument to the print
> statement, a string that you've already formatted with the % operator.
>
> os.path.join is better for dealing with file paths, of course, but
> this will be useful for other things you might want to concatenate and
> format.
>
> -Mike
>
>
>
More information about the Python-list
mailing list