我有一个python类"foo",其中包含:
假设没有反向引用(循环),是否有一种简单的方法来衡量"foo"对象的总内存使用量?
基本上,我正在寻找"sys.getsizeof" 的递归版本
少数的,我碰到的工具包括:heapy,objgraph和GC,但我不认为任何人都能够胜任工作(我可以在此进行校正)
建议赞赏!
经过Matlab多年的研究编程,我想念我可以在执行中暂停程序并检查变量,通过交互式控制台绘制,保存/修改数据等,然后恢复执行.
有没有办法在python中做同样的事情?
例如:
# ... python code ...
RunInterpreter
# Interactive console is displayed, so user can inspect local/global variables
# User types CTRL-D to exit, and script then continues to run
# ... more python code ...
Run Code Online (Sandbox Code Playgroud)
这将使调试变得更容易.建议非常感谢,谢谢!
我正在使用PyQt,并希望基于字符串列表创建菜单.
问题是,当我想调用'addAction'时,它需要一个不带任何参数的回调函数(对于每个字符串).
对于简单的菜单,这很好:例如
menu.addAction("Open", self.open)
menu.addAction("Exit", self.quit)
Run Code Online (Sandbox Code Playgroud)
但是,我想只使用一个函数并将'action string'作为参数传入.
我想知道python是否可以做这样的事情:
def f(x, y):
print x + 2*y
# These 2 variables are of type: <type 'function'>
callback1 = f
callback2 = f(x=7, *)
# NB: the line above is not valid python code.
# I'm just illustrating my desired functionality
print callback1(2,5) # prints 12
print callback2(5) # prints 17
Run Code Online (Sandbox Code Playgroud)
这是我的代码片段:
def printParam(parameter):
print "You selected %s" % parameter
# parameters = list of strings
menu_bar = QMenuBar()
menu = …Run Code Online (Sandbox Code Playgroud)