[Scribus] Re: Bug in calendar script: python is the reason (Eilert)]

Craig Ringer craig
Thu Oct 28 14:27:01 CEST 2004

On Thu, 2004-10-28 at 19:11, Elmar Jobs wrote:

> import sys
> sys.setdefaultencoding('utf-8')   # or ISO8859-1
> at the top of the script. I might be that your distribution prohibits
> setting this value (than the function is unknown).
> For SuSE I had to edit /usr/lib/python/site.py and remove the two lines
> 	if hasattr(sys, "setdefaultencoding"):
> 	    del sys.setdefaultencoding

have some more info on this.

site.py provides configuration options to let Python follow the encoding
specified by the locale:

if 0:
    # Enable to support locale aware default string encodings.
    import locale
    loc = locale.getdefaultlocale()
    if loc[1]:
        encoding = loc[1]

so you should just be able to set that to 'if True' instead if you
prefer. I'd suggest reading the file first to decide what the best
approach really is.

To check the default encoding the Python interpreter is using, run
sys.getdefaultencoding() . Scripts might be wise to check this and
complain if it's inappropriate, though the encoding comment I mentioned
in my last message should reduce the need for this.

I must admit that I'm getting some odd behaviour still - in particular,
I can say:

print u'März'

in a script that declares its self to be utf-8 encoded and everything
works fine. I can also omit the 'u' and things still work correctly. If
I try to use the explicitly unicode form in the interactive interpreter,
I get this printed instead:

so it's clear there's plenty I still need to learn about string handling
in Python. Check out the attached example to see what I mean (try
running the same commands interactively and see what happens).

Anyway, hope this helps.

Craig Ringer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.py
Type: text/x-python
Size: 234 bytes
Desc: not available
Url : http://nashi.altmuehlnet.de/pipermail/scribus/attachments/20041028/5eb391bb/attachment.py 

More information about the scribus mailing list