Create a module function alias by importing or assigning

Let's say that I imported the module using

import m

and now I want to use an alias for my function, I can use

from m import f as n

or

n = m.f

I think there is no difference, preferable to another?

+4
source share
2 answers

There is no difference regarding the use of the object n.

There is a slight logical difference: the first method will leave the name mbound in scope, and the second will not. Although the module mwill still load in sys.moduleswith any approach.

Using the import statement for this is most often considered.

+2
source

, f. , , f (m ). , .

0

Source: https://habr.com/ru/post/1694415/


All Articles