LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > CGI/Perl/Python > Python: Reading unicode data from server and writing to a file

Reply
 
Thread Tools Display Modes
  #1  
Old 11-16-2012, 06:02 AM
thx_for_sharing thx_for_sharing is offline
New Member
 
Join Date: Nov 2012
Posts: 2
Default Python: Reading unicode data from server and writing to a file

Hello,
I am fetching some strings from a server which have one utf-8 character. What I need to do is split on that UTF character and store the parts separately at 2 different places.
For example: 詳細2.3

The '' in the above string is nothing but U+F8FF unicode character (UTF8: EF A3 BF)

I need to split the string on unicode character.
Here is my code:
---------------------------------------
text = open(r"C:\tempchar.txt").read()

newpart = text.decode('utf-8').split(u"\uf8ff")
firstpart = newpart[::2] #some manipulation on this later
secondpart = newpart[1::2] #some manipulation on this later

--------------------------------------
When I try this on a sample string from the text file as done in the code above, it works fine. And I can print the text on cmd prompt.

But, when I do the same thing with the input string from a server, I get the following error:
"UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-9: ordinal not in range(128)

I have never seen this error before and have no idea what could be causing this. PLEASE HELP!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:52 PM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.