Sunday 15 May 2011

python - cannot concatenate 'str' and 'float' objects -



python - cannot concatenate 'str' and 'float' objects -

i trying concatenate string list values in order add together html attributes, error:

cannot concatenate 'str' , 'float' objects

productlist = ["pedegree","chum", "colesbrand"] pricelist = [6,5,3] priceandproduct = [] x,val in enumerate(productlist): priceandproduct.extend([productlist[x],pricelist[x]]) myhtml = "" x in priceandproduct: myhtml = myhtml + x + "<br/>" print priceandproduct

i presume because of elements of type float , string. tried converting each element string , effort concatenation.

x in priceandproduct: x = str(x)

this no avail.

if wanted modify list, following:

priceandproduct = [ str(x) x in priceandproduct ]

python web2py

No comments:

Post a Comment