| Reply | « Previous Thread | Next Thread » |
|
when i use this character = ş , ü ,ö ,ç ,ı
an i take this error: UnicodeError:ASCII encoding error: ordinal not in range(128) |
| cool_eagle |
| View Public Profile |
| Find all posts by cool_eagle |
|
Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
|
Quote:
i think you must use unicode encoding before using these characters. it will be better if you post a bit of code you are using. Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
Quote:
![]() |
| cool_eagle |
| View Public Profile |
| Find all posts by cool_eagle |
|
You can do something like this,
Code:
a = u'ş' print ord(a) #You will get 351 in return IDEAS is all they need but still they think only Genius can give them that. |
| shubhendra |
| View Public Profile |
| Find all posts by shubhendra |
|
@cool_eagle
the "problem" basically is, that python uses ascii as it's defaultencoding, and standard ascii does not have those characters like "äöüß", which is why python can't encode the charakters with the ascii-codec... there are basically two solutions: 1. set the defaultencoding to something supporting your needed characters (UTF-8 covers pretty much everything you'll need). you do so by putting this at the start of the code: Code:
import sys
sys.setdefaultencoding('utf-8')
the more elegant way is, as postet before, the use of unicode. one notice besides: unicode itself isn't really an encoding. you can't save files as unicode, they have to be encoded with something like latin-1, ascii or utf-8... the general rule would be: - when you load strings, DEcode them to unicode - when you save them, ENcode them to encoding-xyz Code:
>>> # Decoding to unicode
>>> input_s = 'äöüß'
>>> repr(input_s)
>>> "'\\xe4\\xf6\\xfc\\xdf'" # this is cp1252
>>> uni = input_s.decode('cp1252)
>>> repr(uni)
>>> "u'\\xe4\\xf6\\xfc\\xdf'" # this is unicode
>>> # cp1252 is the encoding used on my windows-pc,
>>> output_s = uni.encode('utf-8')
>>> repr(output_s)
>>> "'\\xc3\\xa4\\xc3\\xb6\\xc3\\xbc\\xc3\\x9f'" # this is utf-8
Python-Stuff I work on @ http://www.daniel-perna.de/Python.htm |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| CPbkContactEditorDlg customize | asdfghjkl_asdfghjkl | General Symbian C++ | 5 | 2008-08-05 03:56 |
| 编译3rd Sample程序时的LINK错误 | mapk | Symbian | 9 | 2008-06-17 05:26 |
| carbide build problem help please | berkcekisbas | Carbide.c++ IDE and plug-ins | 1 | 2006-09-26 20:41 |
| S80 Platform SDK and Visual Studio .NET Linking Error | jayantjain | Mobile Java Tools & SDKs | 1 | 2005-10-07 23:14 |
| User break point error in Grid | ag24master | Symbian User Interface | 0 | 2003-08-07 09:20 |