Question

[Solved] Why do I get the error “TypeError: coercing to Unicode: need string or buffer, int found”?

After running this small program:

#!/usr/bin/env python2.7
# -*-coding:utf-8 -*
a = 1
b = 2
c = 3
title = u"""a=""" + a + u""", b=""" + str(b) + 
    u""", c=""" + str(c)
print(title)

I get the following error:

u""", c=""" + str(c)
TypeError: coercing to Unicode: need string or buffer, int found

But the following runs just fine!

#!/usr/bin/env python2.7
# -*-coding:utf-8 -*
a = 1
b = 2
c = 3
title = u""", b=""" + str(b) + 
    u""", c=""" + str(c)
print(title)

Can somebody please explain me what is going on?

Enquirer: Agmenor

||

Solution #1:

You didn’t wrap a in a str call. You need to do str(a) where you have a, just like you did for b and c.

Respondent: BrenBarn

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy