You Are Here:

Community: Developer Discussion Boards

#1 Old ACII encoding error?? - 2008-08-23, 12:59

Join Date: Aug 2008
Posts: 148
cool_eagle
Offline
Regular Contributor
when i use this character = ş , ü ,ö ,ç ,ı
an i take this error:
UnicodeError:ASCII encoding error: ordinal not in range(128)
Reply With Quote

#2 Old Re: ACII encoding error?? - 2008-08-23, 13:17

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by cool_eagle View Post
when i use this character = ş , ü ,ö ,ç ,ı
an i take this error:
UnicodeError:ASCII encoding error: ordinal not in range(128)
hi cool_eagle
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
Reply With Quote

#3 Old Re: ACII encoding error?? - 2008-08-23, 14:44

Join Date: Aug 2008
Posts: 148
cool_eagle
Offline
Regular Contributor
Quote:
Originally Posted by gaba88 View Post
hi cool_eagle
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.
can u give me an example
Reply With Quote

#4 Old Re: ACII encoding error?? - 2008-08-23, 18:57

Join Date: Dec 2007
Posts: 409
Location: Tempe, AZ
Send a message via Yahoo to shubhendra Send a message via Skype™ to shubhendra
shubhendra's Avatar
shubhendra
Offline
Forum Nokia Champion
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.
Reply With Quote

#5 Old Re: ACII encoding error?? - 2008-08-24, 01:29

Join Date: Mar 2008
Posts: 35
Location: Frankfurt, Germany
szallah
Offline
Registered User
@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')
however, this method is VERY unelegant, and if your also coding python on your pc it won't even work (because you can't change the deaultencoding that way on a pc).

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
hope this helps...


Python-Stuff I work on @
http://www.daniel-perna.de/Python.htm
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia