How can we make __future__ imports global?

前端 未结 2 397
-上瘾入骨i
-上瘾入骨i 2021-02-05 11:43

Specs: Python 2.7

I\'m working on a project that has several modules, I want to activate some features from the __future__ module in all of them. I would like to import

2条回答
  •  星月不相逢
    2021-02-05 12:42

    Another approach would be using isort. isort has a -a command line flag to add imports to files that you specify. Simply running isort without arguments will run it recursively on all python files in the current working directory and all subdirectories.

    If, like me, you have a virtual environment inside that folder, and are using git (or have an equivalent way of listing only your files) and don't want to run it on all files inside that virtual environment, you can use something like:

    git ls-tree -r HEAD --name-only | grep "\.py$" | xargs isort -a -y "from __future__ import division"

提交回复
热议问题