automatically import module when run python script?

后端 未结 2 460
独厮守ぢ
独厮守ぢ 2021-01-19 15:14

I think other may ask this before but I cannot find it. My question is, I have these statements in my .ipython/ipy_user_conf.py:

ip.ex(\'import          


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-19 16:02

    It's bad practice to have a script which depends on an external startup script to make it work. Doing these imports is how you should do it.

    You could simplify it if you regularly import a fairly large set of things by centralising your imports in a file (call it common_imports.py, for example), and then importing all from that (from common_imports import *). That then becomes only one line to put in. I would still prefer to see explicit imports, however.

    (Another note: in import os as os, the as os is entirely superfluous.)

提交回复
热议问题