| | |
Converting to unicode
![]() |
•
•
Join Date: Oct 2008
Posts: 55
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Oct 2008
Posts: 55
Reputation:
Solved Threads: 0
the following is a function within a 'worddocument' class. It basically parses tables in word documents. anyone know how to convert this to unicode. Its type is instance. Converting it to string will raise an error
python Syntax (Toggle Plain Text)
def GetTables(self): doc = self.app.Documents[0] tables = [] result=[] for word_table in doc.Tables: rows = [] for word_row in word_table.Rows: yield(word_row)#cannot convert to unicode
•
•
Join Date: Oct 2008
Posts: 55
Reputation:
Solved Threads: 0
anyone know anything about encoding. The actual character that is throwing the error is a 1/2 symbol. Could I do
python Syntax (Toggle Plain Text)
x='some string' for each_letter in x: try: each_letter.encode(#what goes here?) except: try: #some other encoding format??
•
•
Join Date: Oct 2008
Posts: 55
Reputation:
Solved Threads: 0
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
"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
![]() |
Similar Threads
- Converting this code to support Windows 98 (Assembly)
- Converting lowercase to uppercase (Java)
- Strange wofstream problem /bug (C++)
- The difference of '\n' in windows and linux. (C++)
- Unknown EMF record types when converting to PDF (Visual Basic 4 / 5 / 6)
- JEditorPane Display Errors (Java)
- Advanced : Reading Memory and Comparing (C)
Other Threads in the Python Forum
- Previous Thread: Absurd Loop Problem
- Next Thread: multiple clients one server
| Thread Tools | Search this Thread |
abrupt accessdenied advanced ansi anti apache application approximation argv array backend beginner binary builtin calculator change command converter countpasswordentry csv curved dan08 def dictionary edit event file float format function google heads homework inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook pointer prime programming py2exe pygame pyopengl python random recursion redirect remote return reverse scrolledtext session software sprite statictext statistics string strings syntax terminal text thread threading time tlapse tuple twoup ubuntu unicode unit urllib urllib2 variable voip wordgame write wxpython





