473,473 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sys.setdefaultencoding

Can someone explain the rationale of making the default encoding a sitewide setting?

I could live with the the default being set on a per process basis, but it
baffles me why even that possibility is taken away as site.py removes
sys.setdefaultencoding.

Is there a way to allow the process to specify that unicode-->str should use
'utf8' rather than 'ascii' in all non-specific cases?
--
Robin Becker

Aug 28 '07 #1
1 4118
Is there a way to allow the process to specify that unicode-->str should
use 'utf8' rather than 'ascii' in all non-specific cases?
No. Things might break if you change the default encoding to anything
but ASCII, and more so if you do that "at runtime". For example,
dictionaries with Unicode keys may stop working, and the cached
byte-oriented version of a Unicode string may become incorrect.

In general, programs and libraries should not rely on the default
encoding for anything. Instead, they should convert explicitly,
either from an explicitly specified encoding, or one derived from
the context. Experience has shown that this is possible in nearly
every case (and in all cases if an appropriate refactoring is made).

Regards,
Martin
Aug 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: christof hoeke | last post by:
hi, i wrote a small application which extracts a javadoc similar documentation for xslt stylesheets using python, xslt and pyana. using non-ascii characters was a problem. so i set the...
3
by: F. GEIGER | last post by:
When I start a py2exe-ed application I get the error 'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in range(128) This is how I run py2exe: setup.py py2exe -O1...
1
by: Paulo da Silva | last post by:
Hi. I am using unicode encode method to write some accented chars to files (%s). Do I need to use the method "encode" always? Isn't there a general way to declare the encoding for the whole...
5
by: Askari | last post by:
Where is the method : "sys.setdefaultencoding(name)"? Problem : I want change the default encoding because I want put french letter : éÉàÀ...etc in widget with no problem! When I use the method...
2
by: Uwe Mayer | last post by:
Hi, well, I wrote a nice python program which won't work if the default encoding has not been set from ascii to latin-1 or latin-15. However, the command sys.setappdefaultencoding is missing...
2
by: Ben Edwards (lists) | last post by:
I am using python 2.4 on Ubuntu dapper, I am working through Dive into Python. There are a couple of inconsictencies. Firstly sys.setdefaultencoding('iso−8859−1') does not work,I have to...
6
by: Franz Steinhaeusler | last post by:
Hello NG, a little longer question, I'm working on our project DrPython and try fix bugs in Linux, (on windows, it works very good now with latin-1 encoding). On Windows, it works good now,...
11
by: =?iso-8859-9?q?S=F6nmez_Kartal?= | last post by:
Hello, I've had an encoding issue and solved it by "sys.setdefaultencoding('utf-8')"... My first try wasn't successful since setdefaultencoding is not named when I imported sys module. After,...
2
by: smalltalk | last post by:
>>import sys Traceback (most recent call last): File "<interactive input>", line 1, in <module> AttributeError: 'module' object has no attribute 'setdefaultencoding' but i find the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.