python什么是函数的唯一标识_Python:从modu中唯一标识一个函数

My original problem is to check within a function if a module function is callable.Therefore the same function can be called in several different ways.

是的,但它是同一个物体。您只需使用f is g来测试f和{}是否是同一个对象。在

更新:为什么需要使用唯一的ID?说真的,别这样。您使用is进行身份测试,使用__hash__方法定义适用的哈希函数。在It would be fantastic to have the actual call alias to it.

不知道你的意思,但我想你只是希望它永远是一个物体。已经是了。在mod is mathematical function and sys.mod returns a list of loaded modules, but python (2.7) does not complain to from sys import mod. I find this a bit awkward?

那就别那么做了。你知道import ... as语法。另外,默认情况下,mod不在全局命名空间中(操作符%用于此)。在

最后,python确实抱怨您的导入行:>>> from sys import mod

Traceback (most recent call last):

File "", line 1, in

ImportError: cannot import name mod

(感谢金多尔指出这一点)。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值