Ulysses
Ulysses

Reputation: 357

Automatic imports from imported file

I have a file called utils.py with the following code:

from __future__ import division
import numpy as np

In another file test.py I call the previous one:

from utils import *
print np.sqrt(4)
print 1/2

Now, as an outcome I get 2 and 0. That is, np imported in utils.py also imports to test.py through utils.py, however the division module does not. Is there a way to make sure division is imported to test.py by importing everything from utils.py?

The motivation is that in almost all my files I import utils.py so I do not want to import division in each file separately, as I can currently do with np.

Upvotes: 0

Views: 40

Answers (1)

Bakuriu
Bakuriu

Reputation: 101919

Imports from __future__ are not real imports! They are a different kind of statement that happen to have a similar syntax.

The documentation states clearly:

It allows use of the new features on a per-module basis before the release in which the feature becomes standard.

They are a way to tell python to treat that file in a different way, in particular to compile the code using a possibly different syntax or semantics.

So, no you cannot "re-export" __future__ imports.

Upvotes: 4

Related Questions