473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

making 'utf-8' default codec

Hi there,

Is there a way of making 'utf-8' default codec for the whole program, so
I don't have to do .encode('utf-8') every time I print out a string?

--
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"
Feb 27 '06 #1
4 2153
Nikola Skoric napisał(a):
Is there a way of making 'utf-8' default codec for the whole program, so
I don't have to do .encode('utf-8') every time I print out a string?


Bad idea. You may accidentally break some libraries that depend on ASCII
being default & standard.

--
Jarek Zgoda
http://jpa.berlios.de/
Feb 27 '06 #2
Nikola Skoric wrote:
Is there a way of making 'utf-8' default codec for the whole program, so
I don't have to do .encode('utf-8') every time I print out a string?


Explicit is better than implicit (so setting up a default codec is
considered bad practice). However, you could wrap an output destination
with an encoder and get the effect you want.

import sys, codecs
sys.stdout, _held = (codecs.getwriter('utf-8')(sys.stdout),
sys.stdout)

--Scott David Daniels
sc***********@acm.org
Feb 27 '06 #3
Jarek Zgoda <jz****@o2.usun.pl> writes:
Bad idea. You may accidentally break some libraries that depend on ASCII
being default & standard.


And what would those produce as output when fed with unicode data? How would
they handle this input? IMVHO nothing should rely on having a standard
charset as input. If it is required, then the library should set it up by
itself: explicit is better than implicit.

--
Jorge Godoy <go***@ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Feb 27 '06 #4
Jorge Godoy napisał(a):
Bad idea. You may accidentally break some libraries that depend on ASCII
being default & standard.


And what would those produce as output when fed with unicode data? How would
they handle this input? IMVHO nothing should rely on having a standard
charset as input. If it is required, then the library should set it up by
itself: explicit is better than implicit.


Besides that, changing default encoding will make program nearly
absolutely unportable as Python by default installs nearly everywhere
with ASCII as default encoding (with iSeries being the only exception
known to me).

--
Jarek Zgoda
http://jpa.berlios.de/
Feb 27 '06 #5

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

Similar topics

6
by: Brian | last post by:
Greetings, I'm working on a project that involved that has need of a categorization system. Logically speaking, the system will have elements, these elements will belong to at least a single...
9
by: lawrence | last post by:
Someone on www.php.net suggested using a seems_utf8() method to test text for UTF-8 character encoding but didn't specify how to write such a method. Can anyone suggest a test that might work?...
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
3
by: TonyJeffs | last post by:
This isn't really a Javascript question - apologies if inappropriate- I don't know where to ask. This code in my website works fine on some pcs - it automatically loads media player and plays...
6
by: archana | last post by:
Hi all, can someone tell me difference between unicode and utf 8 or utf 18 and which one is supporting more character set. whic i should use to support character ucs-2. I want to use ucs-2...
7
by: Jimmy Shaw | last post by:
Hi everybody, Is there any SIMPLE way to convert from UTF-16 to UTF-32? I may be mixed up, but is it possible that all UTF-16 "code points" that are 16 bits long appear just the same in UTF-32,...
10
by: Jed | last post by:
I have a form that needs to handle international characters withing the UTF-8 character set. I have tried all the recommended strategies for getting utf-8 characters from form input to email...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
21
by: Roman Mashak | last post by:
Hello, given a simple code: #include <math.h> long hyp(long height, long base) { return sqrt(height * height + base * base); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.