Re: How do I get unicode support in python?

2008-02-09 Thread Eric Mesa
Message: 12
> Date: Fri, 8 Feb 2008 16:06:50 +0100
> From: "Heiko Wundram (Beenic)" <[EMAIL PROTECTED]>
> Subject: Re: How do I get unicode support in python?
> 0: ordinal not in range(128)
> >>> print u"\xfa".encode("latin-1")
> ú
> >>>
>
> HTH!
>
> --
> Heiko Wundram
> Product & Application Development
>
>
> --
>
>
>
The .encode solution worked perfectly for me!  I am using it for the page
you get when you fill out the year here:
http://server.ericsbinaryworld.com/viet_zodiac_intro.html
(right now you have to switch to utf-8, I haven't set it to do that
automatically yet)

Thanks again!
-- 
Eric Mesa
http://www.ericsbinaryworld.com
http://server.ericsbinaryworld.com
"Do not worry about those things that are outside of your circle of
influence.  For since they are outside of your power to control them it is
simply a waste of time and energy to dwell on them.  Instead, turn your
attention to those things that you can control and grow your influence in
those areas and you will see the effects begin to trickle out to those items
that were previously out of your power to influence." – Eric Mesa inspired
by Covey's 7 Habits of Highly Effective People
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: How do I get unicode support in python?

2008-02-08 Thread Heiko Wundram (Beenic)
Am Freitag, 8. Februar 2008 15:26:48 schrieb Eric Mesa:
> I'm running a web server with FreeBSD 6.1-RELEASE and python 2.4.3.  I'm
> unable to print any characters outside of ascii.  I have tried this code on
> my Linux computer, which has python 2.5.x and it works - so the code is
> solid.
>
> What do I need to do to get python on the web server to have unicode
> support?  Is there a module/package I need to import in the 2.4 series?  Or
> is there some package/port I need to install?  Or do I just recompile
> python with some different flags?  (And does that entail any uninstalling
> first?)

For Python to be able to "print" unicode characters to the console, it must 
know the encoding of the console. Generally, this entails setting up LC_ALL 
and LANG and of course your terminal (emulator) appropriately, and testing 
whether the interpreter sets the correct encoding on startup (which can be 
found as sys.getdefaultencoding()). When the encoding that the interpreter 
uses to "print" _unicode_-strings cannot encode the unicode characters you 
hand it to the current default encoding, the codec barfs:

[EMAIL PROTECTED] ~]$ python
Python 2.5.1 (r251:54863, Nov  6 2007, 19:02:51)
[GCC 4.2.1 20070719  [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>> print u"\xfa"
Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfa' in position 
0: ordinal not in range(128)
>>> print u"\xfa".encode("latin-1")
ú
>>>

Basically, the easiest resolution is to do the conversion yourself (like I did 
in the second example). The other possibility is to change the deault 
encoding to something that matches your default console (probably latin-1), 
which you can do in /usr/local/lib/python2x/site.py.

HTH!

-- 
Heiko Wundram
Product & Application Development
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


How do I get unicode support in python?

2008-02-08 Thread Eric Mesa
I'm running a web server with FreeBSD 6.1-RELEASE and python 2.4.3.  I'm
unable to print any characters outside of ascii.  I have tried this code on
my Linux computer, which has python 2.5.x and it works - so the code is
solid.

What do I need to do to get python on the web server to have unicode
support?  Is there a module/package I need to import in the 2.4 series?  Or
is there some package/port I need to install?  Or do I just recompile python
with some different flags?  (And does that entail any uninstalling first?)

Thanks,

-- 
Eric Mesa
http://www.ericsbinaryworld.com
http://server.ericsbinaryworld.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"