7
7stud
Can anyone tell me why I can print out the individual variables in the
following code, but when I print them out combined into a single
string, I get an error?
symbol = u'ibm'
price = u'4 \xbd' # 4 1/2
print "%s" % symbol
print "%s" % price.encode("utf-8")
print "%s %s" % (symbol, price.encode("utf-8") )
--output:--
ibm
4 1/2
File "pythontest.py", line 6, in ?
print "%s %s" % (symbol, price.encode("utf-8") )
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
2: ordinal not in range(128)
following code, but when I print them out combined into a single
string, I get an error?
symbol = u'ibm'
price = u'4 \xbd' # 4 1/2
print "%s" % symbol
print "%s" % price.encode("utf-8")
print "%s %s" % (symbol, price.encode("utf-8") )
--output:--
ibm
4 1/2
File "pythontest.py", line 6, in ?
print "%s %s" % (symbol, price.encode("utf-8") )
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
2: ordinal not in range(128)