Why does an imported function “as” another name keep its original __name__?

后端 未结 3 1303
别那么骄傲
别那么骄傲 2021-02-12 19:09

Here:

from os.path import exists as foo
print foo.__name__

we get: \'exists\'. Why not \'foo\'? Which attribute would

3条回答
  •  感情败类
    2021-02-12 19:28

    The as is syntactical sugar in the file/session of the import, while the __name__ attribute is part of the function object.

提交回复
热议问题