I'm looking for a way to convert a variable (which could be an ASCII string, unicode string WITH extra characters like é or £, or a floats or integer) into a unicode string.
variable.encode('utf-8')
where variable
is an integer results in AttributeError: 'int' object has no attribute 'encode'
str(variable).encode('utf-8')
where variable
is the string '£'
results in UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)
Is there an easy way to do what I'm looking for in Python 2.7? Or do I have to check the type of variable and process it differently?