Is there a performance cost putting python imports inside functions?

后端 未结 3 1633
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 00:53

I build quite complex python apps, often with Django. To simplify inter-application interfaces I sometimes use service.py modules that abstract away from the models.

As

3条回答
  •  故里飘歌
    2021-02-04 01:15

    See this question.

    Basically whenever you import a module, if it's been imported before it will use a cached value.

    This means that the performance will be hit the first time that the module is loaded, but once it's been loaded it will cache the values for future calls to it.

提交回复
热议问题