Python: Encoding latin-1 utf-8

#!/usr/bin/python
# coding: latin-1

If script is stored in utf-8, a u character has to appear before any utf-8 strings, as in following example:

#!/usr/bin/python
# coding: utf-8

(....)

ws.write_string ("B6",u'Ñéñººª')

For cygwin users, python should be manually pointed at windows python available.

 ln -s  /cygdrive/c/Python27/python.exe /usr/bin/python

If encoding is not set up:

$ python fmyscript.py
  File "fmyscript.py", line 20
SyntaxError: Non-ASCII character '\xc3' in file ficha_conecta.py on line 20, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

To learn more about encoding: https://www.python.org/dev/peps/pep-0263/

 

 

Autor: Ester Niclós Ferreras

http://www.linkedin.com/pub/ester-niclos-ferreras/9/887/3b4

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *