Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use "from __future__ import unicode_literals" in a master import file?

Tags:

python

I'm creating some demonstration Python scripts that must work under 2.6, 2.7, and 3.3.

As part of that, each module is prefixed with

from __future__ import unicode_literals

Can this directive be cut from each of the modules and pasted into a common import file instead?

E.g.

# master.py
from __future__ import unicode_literals

# file1.py
import master

# file2.py
import master
like image 952
bluedog Avatar asked Aug 27 '13 02:08

bluedog


2 Answers

No. Quoting the documentation:

A future statement is a directive to the compiler that a particular module should be compiled using syntax or semantics that will be available in a specified future release of Python.

(http://docs.python.org/2/reference/simple_stmts.html#future)

The __feature__ imports affect only the current module.

like image 134
viraptor Avatar answered Oct 02 '22 13:10

viraptor


No. Compiler flags (which is how __future__ is implemented) only affect compilation of the current module.

like image 34
Ignacio Vazquez-Abrams Avatar answered Oct 02 '22 14:10

Ignacio Vazquez-Abrams