0

Isn't it possible to tell your python interpreter to consider by default all .py files as encoded in utf-8??

While this is not good for portability as you may then forget to place the # -*- coding: utf-8 -*- kind of headers,

it is today a pain for me to have to always have to remember to write this header when writing short temporary scripts with unicode strings inside.

(for example when working on remote envs, I don't use a full-bundled-and-configured editor which could systematically add the header for me, so I have to remember that detail)

lajarre
  • 4,910
  • 6
  • 42
  • 69

1 Answers1

3

You can do a few tricks, but none are that great IMO. The "solution" is to move to Python 3.

When you initialize your shell/python, you can do this hack which is not 100% full-proof:

#!/usr/bin/python2.7 -S

import sys
sys.setdefaultencoding("utf-8")
import site

This trick is not such a great idea, but maybe should meet your needs for remote shells and such to test things quickly.

See this and this for more info and discussion of the drawbacks. (Possible duplicates).

Community
  • 1
  • 1
therewillbesnacks
  • 1,015
  • 6
  • 8