Python技巧之超棒的内建函数:globals()和locals()

globals()返回一个字典,其包含当前上下文所有的全局变量。

locals()干的是一样的活,但返回的

# "globals()" returns a dict
# with all global variables
# in the current scope:

>>> globals()
{...}

# "locals()" does the same
# but for all local variables
# in the current scope:

>>> locals()
{...}

评论

暂无评论