查看所有定义的变量 [英] Viewing all defined variables
本文介绍了查看所有定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在 python shell 中进行计算.我想要的是 Matlab 样式的列表,您可以在其中查看已定义的所有变量(因此我知道我使用了哪些名称、它们的值等).
I'm currently working on a computation in python shell. What I want to have is Matlab style listout where you can see all the variables that have been defined up to a point (so I know which names I've used, their values and such).
有没有办法,我该怎么做?
Is there a way, and how can I do that?
推荐答案
一些你可以使用的东西:
A few things you could use:
dir()
会给你范围内变量的列表:globals()
会给你一个全局变量字典locals()
会给你一个局部变量字典
dir()
will give you the list of in scope variables:globals()
will give you a dictionary of global variableslocals()
will give you a dictionary of local variables
这篇关于查看所有定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文