سؤال

I'm new to python. I'm trying to print accented characters, like this:

    # -*- coding: utf-8 -*-
    print 'éàÇÃãéèï'

But when I execute this code, I get:

    >> ├®├á├ç├â├ú├®├¿├»

I'm using 64-bit Windows 7 & Python 2.7.5, I have the code in file.py and execute it with

python file.py
هل كانت مفيدة؟

المحلول

As Wooble mentioned, if you change

print 'éàÇÃãéèï'

to

print u'éàÇÃãéèï'

It should work.

Here is a good intro to unicode in python (both for 2.x and 3): The updated guide to unicode

نصائح أخرى

import sys
sys.stdout.reconfigure(encoding='utf-8')

print('Now it works éàÇÃãéèï')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top