newb: Join two string variables
John Machin
sjmachin at lexicon.net
Tue Dec 5 20:04:02 EST 2006
johnny wrote:
> In my code, I have the following:
>
> p = posixpath.basename(e).strip
> filename = download_dir+p
>
> I am getting the following error:
>
> filename = download_dir+p
> TypeError: cannot concatenate 'str' and 'builtin_function_or_method'
> objects
>
>
You need to *call* the strip method.
To see what you've actually done, do this:
p = posixpath.basename(e).strip
print repr(p)
filename = download_dir+p
To see what happens when you've fixed the problem, do this:
p = posixpath.basename(e).strip()
print repr(p)
filename = download_dir+p
*and* for portability, *don't* use "posixpath", just use "path"
HTH,
John
More information about the Python-list
mailing list