- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
根据docs :
inspect.currentframe()
Return the frame object for the caller’s stack frame.
CPython implementation detail: This function relies on Python stack frame support in the interpreter, which isn’t guaranteed to exist in all implementations of Python. If running in an implementation without Python stack frame support this function returns None.
怎么只有这个函数被标记为“implementation-dependent”?如果这个功能不行,那inspect.trace
、inspect.stack
等类似功能不也无法使用吗?
此外,“堆栈框架支持”是什么意思,为什么它会不存在?
最佳答案
inspect.currentframe
的可用性与 sys._getframe
相关:
def currentframe():
"""Return the frame of the caller or None if this is not possible."""
return sys._getframe(1) if hasattr(sys, "_getframe") else None
因此,该限制适用于所有其他也使用 sys._getframe
的函数。对于 inspect
,这只是 inspect.stack
。
相比之下,inspect.trace
使用sys.exc_info
。这是异常处理方案的组成部分,应该始终可用。所有其他相关功能,例如getframeinfo
,已经依赖有框架了。它们的适用性取决于您是要检查异常还是调用回溯。
请注意,我的本地默认 jython 确实支持 sys._getframe
。如果使用 -X:Frames
运行,ipy 可以工作。
关于python - inspect.currentframe() 在某些实现下可能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938980/
我有一个嵌套数组: array_name = [ ["Alice", "pizza", "soccer"], ["Steve", "sushi", "hockey"], ["Alex",
我正在尝试下载网页,但文件在我下载的内容、页面源和检查方面有所不同。如何下载检查中显示的内容? 最佳答案 查看页面源代码返回服务器发送并由浏览器加载的静态 html 页面。 虽然 inspect 将显
我发现自己在我的功能测试中做了很多 puts .inpsect s 以确保我知道数据是如何格式化的......但是当散列对象中的每个条目之后没有新行时散列很难读取.无论如何,也许是一个 gem ?,
所以这段代码: from inspect import * class X(object): def y(self): pass methods = getmembers(X, predi
我在 Ruby 1.9 中通过调用等于 my_hash.inspect 的 my_hash.to_s 不小心将 Ruby 哈希保存到字符串。这给了我这样的字符串: '{"foo"=>{"bar"=>"
自从升级 NodeJs 以来,我从 Visual Studio 2017 运行 Nodejs 时遇到此错误。 断点也不起作用。有任何解决这个问题的方法吗? 注意:VS版本是15.5.6NodeJS 版
我已经使用 VS 2015 在我的计算机上安装了 nodeJs 并进行了设置。当我尝试运行示例 hello world 应用程序时,它抛出以下错误: verb(node:14096) [DEP0062
当我在 Visual Studio 中运行 Node.js 应用程序时,我收到以下消息:DeprecationWarning: 'node --debug' 和 'node --debug-brk'
下面的代码无法运行 def map = [name:"Test :: ( %2f %25 \$ * & ! @ # ^)"] String s = map.inspect() println Eval
我正在尝试使用检查来查明 foo 是否是对象 test_me 的方法。我希望它返回 True 或 False。这是我试过的。 import inspect class Object: pass
这个问题在这里已经有了答案: Is there a way in git to obtain a push date for a given commit? (8 个答案) 关闭 5 年前。 我如何
描述与简介 docker inspect是docker客户端的原生命令,用于查看docker对象的底层基础信息。包括容器的id、创建时间、运行状态、启动参数、目录挂载、网路配置等等。另外,该命令也
我的问题是如何使 SASS 函数 inspect() 与数组一起工作或如何以另一种方式输出数组。 我的基本示例是这段代码: @function z($layers...) { @warn "`#{
我在 Ruby 中发现了一个奇怪的问题,我不太确定这是一个问题还是最近 Ruby 版本中引入的一个功能。 基本上当我们调用一个未定义的方法时,我们会得到一个 undefined method Ruby
Message will display here Document.getElementById("idbd").style.backgroundcolor="red"; Document
注意:我读过类似的帖子,但没有一个完全是我的问题 - 我可以右键单击它,然后它就消失了。 我发现“检查元素”是 Chrome 中非常宝贵的工具,但是我在将其用作导航栏上某个元素的子菜单时遇到了麻烦,该
使用 ionic 开发 Web 应用程序时,在 iOS 模拟器中使用命令行运行程序非常有用 ionic run ios -l -c -s --target="iPhone-5s" 然后通过选择桌面 S
JQuery 是一个非常强大的工具,但它很难调试。 看看下面的图片: 如何轻松找到包含 JQuery 代码的 *.js 文件,该代码已附加到这部分 HTML 代码? 我认为这几乎是不可能的,因为它也可
我正在尝试通过古腾堡 Inspect Control 的媒体库上传文件。我目前在 JS 中使用此代码: var el = wp.element.createElement, registerB
我正在尝试使用 Is it possible to list all functions in a module? 的答案列出一系列模块中的功能。但在我的解释器中,我得到如下信息: Python 3.
我是一名优秀的程序员,十分优秀!