If you want to add an import line to one or multiple python files, you can achieve this easily using the isort package.
Install isort in your python environment:
Now, execute the next isort command to add an import to multiple python files.
Multiple options can be added to configure how isort works.
For example, imagine you have some changes on your working copy that cause an error because you need an import. If you write this files into a "files.txt" file (one line per file)
Example /tmp/files.txt
As I say before, you can mix with a lot of options, for example this is the command I use to handle line length, indentation, third parties, ...
Hope you found this useful!!
Install isort in your python environment:
pip install -r isort
Now, execute the next isort command to add an import to multiple python files.
Multiple options can be added to configure how isort works.
For example, imagine you have some changes on your working copy that cause an error because you need an import. If you write this files into a "files.txt" file (one line per file)
Example /tmp/files.txt
file1.py controllers/file2.pyCommand line
FILES=$(cat /tmp/files.txt) isort -a "from foo import bar" ${FILES}
As I say before, you can mix with a lot of options, for example this is the command I use to handle line length, indentation, third parties, ...
isort -ac -tc -m 3 -w 119 -i4 -up -y ${FILES}
Hope you found this useful!!
Comentarios
Publicar un comentario