Dan Eloff
dan.eloff at gmail.com
Thu Feb 16 12:10:09 EST 2006
Gustavo, here's an example. Suppose some code enforces a maximum length on a string. If it's counting on a default encoding of 1 byte per char, and does something like len(s) <= 15. For ascii or iso-8859-1 this would work. Or the code might use indices or slices (and a lot of code does!) If suddenly you have utf-8 encoded chinese, your string is going to triple in length, and those functions will have unpredictable behaviour. You could think of any number of scenarios, even in the python library. I just wouldn't feel confortable about changing the default encoding, you never know where it will come back to haunt you. What's so hard about using unicode strings in your program and then encoding when you send output somewhere? Of course, like we've noticed in this thread, there is third party code that just isn't unicode safe like psp in mod_python that will break if you don't mess with the default encoding. It all boils down to seeing what will work best in your situation. For myself I would rather do it the right way up front in the hopes of saving hassles down the road. -Dan On 2/16/06, Gustavo Córdova Avila <gustavo.cordova at q-voz.com> wrote: > > Dan Eloff wrote: > > > Gustavo > > > > "So, if you can configure your default encoding" > > > > That would be a bad idea. You don't want to force the interpreter to > > use a different encoding, it could cause you all manner of grief with > > code that wasn't written for that, and if it's third party code you > > can't do much about anything that does break. > > > Hi Dan, thanks for replying. > > Do you have any examples of the above? I haven't had any troubles > whatsoever using a default encoding, even when the script source is > different from the default encoding (I always use the "-*- coding: xxx > -*-" bit at the top of the source file), so while I don't doubt at all > what you're saying, having a practical case where fiddling with the > default encoding breaks things is good. > > Good morning, y'all. > > -gus > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060216/04cef624/attachment.html
|