win_unicode_console (original) (raw)

A Python package to enable Unicode input and display when running Python from Windows console.

General information

When running Python in the standard console on Windows, there are several problems when one tries to enter or display Unicode characters. The relevant issue is http://bugs.python.org/issue1602. This package solves some of them.

There are additional issues on Python 2.

Installation

Install the package from PyPI via pip install win-unicode-console (recommended), or download the archive and install it from the archive (e.g. pip install win_unicode_console-0.x.zip), or install the package manually by placing directory win_unicode_console and module run.py from the archive to the site-packages directory of your Python installation.

Usage

The top-level win_unicode_console module contains a function enable, which install various fixes offered by win_unicode_console modules, and a function disable, which restores the original environment. By default, custom stream objects are installed as well as a custom readline hook. On Python 2, raw_input and input functions are monkeypatched. sys.argv is not monkeypatched by default since unfortunately some Python 2 code strictly assumes str instances in sys.argv list. Use enable(use_unicode_argv=True) if you want the monkeypathcing. For further customization, see the sources. The logic should be clear.

Generic usage of the package is just calling win_unicode_console.enable() whenever the fixes should be applied and win_unicode_console.disable() to revert all the changes. Note that it should be a responsibility of a Python user on Windows to install win_unicode_console and fix his Python environment regarding Unicode interaction with console, rather than of a third-party developer enabling win_unicode_console in his application, which adds a dependency. Our package should be seen as an external patch to Python on Windows rather than a feature package for other packages not directly related to fixing Unicode issues.

Different ways of how win_unicode_console can be used to fix a Python environment on Windows follow.

Compatibility

win_unicode_console package was tested on Python 3.4, Python 3.5, and Python 2.7. 32-bit or 64-bit shouldn’t matter. It also interacts well with the following packages:

Backward incompatibility

Acknowledgements