8

I have two unicode string '가' and 'ㄱ' and I want to concatenate them to get "가ㄱ"

This is my code:

output1 = unicodeQueue(self.queue) # first unicode result
output2 = unicodeQueue(self.bufferQueue) # second unicode result
sequence = [output1, output2]
print sequence
output = ''.join(sequence)
return output

And this is the output I'm getting:

[u'\uac00', u'\u3131']
ㄱ가가ㄱ가

I don't know why it doesn't produce correct result, can anyone help me with this?

5
  • I am unable to reproduce this. Commented Nov 5, 2012 at 13:51
  • @NPE I uploaded my partial script, the main of my question is "how to concatenate two unicode in python?" Commented Nov 5, 2012 at 13:54
  • @user1732445: there's nothing obviously wrong w/ your code. Commented Nov 5, 2012 at 13:56
  • 1
    Works for me. May be try u''.join(sequence). Commented Nov 5, 2012 at 13:57
  • Same here, nothing wrong with the join, it works as supposed to the unicodeQueue class? Commented Nov 5, 2012 at 14:01

1 Answer 1

7

if you want to concatenate two strings use +

>>> '가' + 'ㄱ'
'\xea\xb0\x80\xe3\x84\xb1'
>>> u'가' + u'ㄱ'
u'\uac00\u3131'
>>> print u'가' + u'ㄱ'
가ㄱ

this means you can use

output1 + output2
Sign up to request clarification or add additional context in comments.

1 Comment

Keep in mind that + works more slowly than unicode.join(u'',vals) or str.join('',vals), but if it works when join doesn't, by all means, use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.