简体   繁体   中英

unicode_literals everywhere in python 2.7

Is there a way to get the behaviour of

from __future__ import unicode_literals

to apply project-wide, apart from putting this import in the top of each and every module?

I would like to just define it in one place, like the __init__.py of the package directory of project root say, and have it recursively apply to subpackages and submodules.

TL;DR - No

Command-line option -U enables unicode globally. From docs :

Turns all string literals into unicodes globally. Do not be tempted to use this option as it will probably break your world. It also produces .pyc files with a different magic number than normal.

You can't use it in practice, though, because it will mess up even the standard library. The docs advise just to enable unicode literals on a per-module basis using the future import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM