What is file.encoding convention?

Vinay Sajip vinay_sajip at yahoo.co.uk
Fri Jul 24 05:14:13 EDT 2009


On Jul 24, 4:10 am, Naoki INADA <songofaca... at gmail.com> wrote:
> > Yes! I confused by it.
>
> s/I confused/I am confused/
>
> > "Writing unicode to a file(-like)" is a simple requirement.
> > Does python have any simple resolution for it?
>
> s/resolution/solution/
>

Of course, Python 3 has much better Unicode support:
---------------------------------------------------------------------
C:\Users\Vinay>chcp 1251
Active code page: 1251

C:\Users\Vinay>\python31\python
ActivePython 3.1.0.1 (ActiveState Software Inc.) based on
Python 3.1 (r31:73572, Jun 28 2009, 19:55:39) [MSC v.1500 32 bit
(Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'cp1251'
>>> u = '\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'
>>> print(u)
до свидания
>>> n = sys.stdout.write(u)
до свидания>>> ^Z
---------------------------------------------------------------------

Regards,


Vinay Sajip



More information about the Python-list mailing list