473,387 Members | 3,033 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,387 software developers and data experts.

Problems with encoding

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 program?
I have tried sys.setdefaultencoding but there was
no such method !

Thanks for any help.
Jul 18 '05 #1
1 1341
Paulo da Silva <ps*********@esotericaX.ptX> wrote:
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 program?
I have tried sys.setdefaultencoding but there was
no such method !


sys.setdefaultencoding gets removed right after the startup phase
(execution of site.py &c), because it's not meant to be called anymore
after that. Nothing stops you from bypassing Python's helpful attempt
to save you from this error: reload(sys) and call sys.setdefaultencoding
at will, just don't complain as and when something should break in
mysterious ways. I suggest forgetting this possibility.

More sensibly, you could use codecs.open, instead of the built-in
function open, to open the files you mean to write to. This way, you
can write Unicode strings to the files directly, and the files will take
care of the encoding. I suggest you explore this idea, which I believe
is much sounder than "declare encoding for the whole program".
Alex
Jul 18 '05 #2

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

Similar topics

1
by: Irmen de Jong | last post by:
Hi I'm trying to create e-mail content using the email.MIMEText module. It basically works, until I tried to send mail in non-ascii format. What I did, to test both iso-8859-15 and UTF-8...
6
by: Gandalf | last post by:
Hi All! I have a program that looks like this: # -*- coding: iso-8859-2 -*- s1 = 'néz' s2 = raw_input('Please type in "néz":') print repr(s1) print repr(s2)
9
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape...
7
by: Stingray | last post by:
Are there any know problems with using a MemoryStream as a backing store for a CryptoStream? I'm trying to simply encrypt and decrypt text in memory. I'd like to create some simple methods to...
15
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
1
by: Yoramo | last post by:
Hello I'm generating a XML document to a StringWriter. using VS 2005 beta 1. I have 2 problems: 1. I can not set the encoding to UTF-8. I'm getting UTF-16 all the time.. 2. The XML document...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
0
by: ben | last post by:
OK so there are a few things going on. I succesfully created a SOAP webreference in VS IDE which when built works fine under small amounts of load, however under heavy amounts of load we start to...
20
by: Chris Withers | last post by:
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg =...
15
by: Bexm | last post by:
Hello I have searched through this forum and it seems some people are having similar problems to me but none of the fixes are fixing mine..! :( I have a table in my database that has two xml...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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...

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.