pdb 中有类似 gdb 的 `x` 命令吗?

Any similar `x` command of gdb in pdb?

通过gdb,我们可以看到内存单元,如(gdb) x /**xb address,帮助我们了解变量实际上是如何保留在计算机中的。 那么我可以用 pdb 来做吗?以及如何?

答案是否定的

pdb 没有这样的选项来执行此操作。('variable' 称为 'reference' 可能更好)。

python中的变量与C/C++不同, 例如:

整数1,在C中他的存储形式:

   0000 0000 0000 0001

但是,在python中,1不是一个纯数,而是一个结构。

如果你看Python-2.7.13\Include\intobject.h

你会看到这个:

typedef struct {
    PyObject_HEAD
    long ob_ival;
} PyIntObject;

我觉得没必要看python中变量的存储形式。

有时我们只需要知道什么是变量。

在这种情况下,您可以使用'p''pp'https://docs.python.org/2/library/pdb.html.

中的文档

p expression

Evaluate the expression in the current context and print its value.

pp expression

Like the p command, except the value of the expression is pretty-printed using the pprint module.