How to specify encoding when running python script as a module?
For example, I want to run my_script.py as python -m my_script -utf8. But there is no such an option. Instead, I should provide my_script.py with encoding on top of the file. And it fails with some python-2.7 packages.
Consider next scenario:
my_script.py:
# coding=utf-8
from pyglet.gl import *
$ cd ~/Documents- create non-ascii folder:
$ mkdir вафля $ cd вафля- create
my_script.pywith the code above python my_script.py-- works wellpython -m my_script-- fails
Work station: Ubuntu 14.04.3 x64 + Python 2.7.6 x64 (built-in)
Do not suggest me to switch on Python 3.4 because I've already done it and just want to support both 2.7 and 3.4 versions of Python.
Added traceback.
File "my_script.py", line 22, in <module>
from pyglet.gl import *
File "/usr/local/lib/python2.7/dist-packages/pyglet/gl/__init__.py", line 236, in <module>
import pyglet.window
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/__init__.py", line 1817, in <module>
gl._create_shadow_window()
File "/usr/local/lib/python2.7/dist-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 163, in __init__
super(XlibWindow, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/__init__.py", line 559, in __init__
self._create()
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 353, in _create
self.set_caption(self._caption)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 511, in set_caption
self._set_text_property('WM_NAME', caption, allow_utf8=False)
File "/usr/local/lib/python2.7/dist-packages/pyglet/window/xlib/__init__.py", line 785, in _set_text_property
buf = create_string_buffer(value.encode('ascii', 'ignore'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 19: ordinal not in range(128)
valueon which the code crashes contains non-unicode path tomy_script.py. If there was an attribute in-moption, I'd pass it to wrapmy_script.py's path in a unicode - if the was a way to addu''character before path value...