问题标签 [inspect]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 获取完整的包模块名称
对于我的应用程序中的详细调试消息,我使用了一个返回有用前缀的函数。考虑以下示例:
这输出:
我的问题是:当我在包中有一个模块时,例如“myproject.utilities.input”,返回的模块名称get_verbose_prefix
仍然只是“input”,而不是“myproject.utilities.input”。当不同的子模块中可能有多个“输入”模块一起工作时,这大大降低了前缀在大型项目中的有用性。
所以我的问题是:有没有一种简单的方法可以在 Python 的包中检索完整的模块名称?我计划扩展该get_verbose_prefix
功能以检查模块父目录中的“__init__.py”文件以推断它的全名,但首先我想知道是否有更简单的方法来做到这一点。
python - Python - How can I query the class in which a method is defined?
My question is somewhat similar to this one; it concerns object methods rather than module contents. I want to know if I can use the inspect
module to get the methods defined only in the class I'm asking about, and not its parent(s).
I need this because my child class defines 'macro' methods, which accesses the parent's methods at a higher level of abstraction, and I don't want the user to have to worry about the lower-level methods defined all the way up the inheritance tree.
Here is a simplified example:
Output:
The user need not know or care about the existence of the f
s since she's only ever going to be interested in the g
s. (Of course, this output makes sense in the vast majority of contexts, since all these methods will be bound to the object when it is instantiated.) For a long inheritance tree, the returned list can get very long and full of things that aren't relevant to the user.
How can I get it to leave f1
and f2
off this list? Is there an equivalent to the __module__
attribute for the methods defined in classes? Better still, is it possible to do the same thing with instance methods?
python - os.chdir 之后inspect.getmodule 的结果变化
我的一些代码似乎突然出现了一个错误。当我追踪它时,我发现inspect.getmodule
在执行之前和之后使用相同(相同)的参数进行评估os.chdir
会产生不同的结果。
(FWIW,我在 OS X 下运行 Python 2.7.3。)
我发现这种行为非常令人费解和困惑,以至于我不知道如何最好地修复这个错误。(换句话说,在了解行为的原因后,我能想到的任何解决方案都只是一个创可贴。)
下面的测试脚本说明了这种行为(当然,现实生活中的错误发生在更加现实和复杂的环境中):
(注意:运行此代码需要在当前目录下立即有一个名为“subdir”的子目录。)
它的输出是:
请注意,尽管所有三个调用getmodule
都具有相同的框架对象作为参数,但最后一个的结果与前两个的结果不同。(正如人们所期望的那样,前两次调用的结果是相同的。)
前两个调用和第三个调用的唯一区别是后者发生在运行之后os.chdir
。
任何有关正在发生的事情的见解将不胜感激。
python - 在python上打印出类参数
我想打印出类 Column 的实例化参数。通常 - python 代码到字符串。例子:
我尝试了检查模块,但发现它不支持它: http ://docs.python.org/library/inspect.html#inspect.getmembers
感谢您提供任何信息
javascript - 从第三方代码中暴露未知的 JavaScript 对象方法
我正在寻找一种方法来公开未知 JavaScript 对象的类型和方法。
我正在实现第三方代码,其方法的文档有限,因此我无权访问任何可以告诉我应该在response
.
有没有办法确定这是什么类型的对象并公开它包含的方法?
Firebug 控制台中的输出:
响应:[对象对象],[对象对象],[对象对象],....
python - 如何在运行时从模块内部知道哪个脚本调用了其中的函数
我在 python 中有一个模块,并且基于在其中调用函数的脚本,我想在该模块中做出决定。
因此,如果我们有 2 个文件file1.py
和file2.py
,则都导入模块 testmod 并在其中调用一个函数。在模块 testmod 中,我想知道哪个脚本调用了它?file1.py
或file2.py
。
我想在 testmod 中编写如下代码 if then do this else if then do that else do something else !
python - 使用检查.getmembers
我正在尝试使用inspect.getmembers
来检查文件中的类和函数。问题是我不知道如何在inspect.getmembers
不使用import
. 那是因为我每次都需要指定不同的文件名
代码与此类似:
assembly - 检查组装中的堆栈
我正在内联汇编中推送一些 int 值:
后来我检索这个值做弹出:
我想在不弹出的情况下检查我的堆栈。我需要重新排列或重新审视一些值。完成后我可以恢复堆栈。
我对asm很生疏。有没有类似的东西:
那会移动下一个(不是当前的)堆栈元素吗?我只是猜测。我需要这段代码在 32 位 win 和 64 win 环境中运行。
python - 计算python文件中每个类的代码行数?
我正在尝试在 python 文件中查找类中的代码行数。我使用 len(inspect.getsourcelines(b)[0]) 返回文件中每个类的代码行数但是除了代码行之外,它还计算注释和文档字符串的问题..有没有办法丢弃注释和文档字符串?