Converting to unicode

Reply

Join Date: Oct 2008
Posts: 57
Reputation: ihatehippies is an unknown quantity at this point 
Solved Threads: 0
ihatehippies ihatehippies is offline Offline
Junior Poster in Training

Converting to unicode

 
0
  #1
Nov 18th, 2008
Does anyone know how to convert an instance to unicode?
I understand how to convert a string into unicode format

u=unicode(s, 'ASCII', ignore), however this assumes that s is already a string and converting s by the str(s) method will kick back an error if s contains unicode unfriendly.
The strings I'm processing are 'instances' and the process works fine until the instance contains a character outside of the normal 128 character range. I found this link that I think is closely related. http://www.python.org/dev/peps/pep-0349/ Does anyone have any experience with this?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 57
Reputation: ihatehippies is an unknown quantity at this point 
Solved Threads: 0
ihatehippies ihatehippies is offline Offline
Junior Poster in Training

Re: Converting to unicode

 
0
  #2
Nov 19th, 2008
the following is a function within a 'worddocument' class. It basically parses tables in word documents.
  1. def GetTables(self):
  2. doc = self.app.Documents[0]
  3. tables = []
  4. result=[]
  5. for word_table in doc.Tables:
  6. rows = []
  7. for word_row in word_table.Rows:
  8. yield(word_row)#cannot convert to unicode
anyone know how to convert this to unicode. Its type is instance. Converting it to string will raise an error
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 57
Reputation: ihatehippies is an unknown quantity at this point 
Solved Threads: 0
ihatehippies ihatehippies is offline Offline
Junior Poster in Training

Re: Converting to unicode

 
0
  #3
Nov 20th, 2008
anyone know anything about encoding. The actual character that is throwing the error is a 1/2 symbol. Could I do
  1. x='some string'
  2. for each_letter in x:
  3. try:
  4. each_letter.encode(#what goes here?)
  5. except:
  6. try:
  7. #some other encoding format??
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 57
Reputation: ihatehippies is an unknown quantity at this point 
Solved Threads: 0
ihatehippies ihatehippies is offline Offline
Junior Poster in Training

Re: Converting to unicode

 
0
  #4
Nov 21st, 2008
as much fun as it is writing to myself.. can someone explain how I use:
"To convert a class instance to Unicode, a __unicode__ method can be defined by a class, analogous to __str__. "

Its found on this link http://www.python.org/doc/2.2.3/whatsnew/node8.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC