Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1175

How to manipulate/join multiple strings containing UTF-8 characters

$
0
0

My code needs to be compatible with both Python 2.x and 3.x versions. I am getting both string as input to my function, and I need to do some manipulation on those:

if len(str1) > 10:    str1 = str1[:10] +'...'if six.PY3:    return ' : '.join((str1, str2))

For Python 2.x, the above join is giving error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)

What is the cleaner way of handling such cases for all versions of 2.x and 3.x?As both the string are input to my code, I need to ensure that even if either of these strings contain UTF-8 characters, they should be joined properly.

Declaration : I am very new to Python.


Viewing all articles
Browse latest Browse all 1175

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>