【发布时间】:2019-01-16 07:34:34
【问题描述】:
在 PyCharm 启动的 Python 控制台中,看起来runfile 是一个导入函数:
In[21]: runfile
Out[21]: <function _pydev_bundle.pydev_umd.runfile(filename, args=None, wdir=None, is_module=False, global_vars=None)>
既然是本地范围内的名字,不应该在dir()的输出中列出吗?
In[22]: print(dir())
['In', 'Out', '_', '_12', '_13', '_14', '_15', '_16', '_17', '_18', '_19', '_21', '_3', '_5', '_6', '_7', '_8', '__', '___', '__builtin__', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_i', '_i1', '_i10', '_i11', '_i12', '_i13', '_i14', '_i15', '_i16', '_i17', '_i18', '_i19', '_i2', '_i20', '_i21', '_i22', '_i3', '_i4', '_i5', '_i6', '_i7', '_i8', '_i9', '_ih', '_ii', '_iii', '_oh', 'a', 'absolute', 'exit', 'get_ipython', 'numpy', 'quit', 'sys']
【问题讨论】:
-
我现在在 Python 教程中看到了这一点:
dir() does not list the names of built-in functions and variables.import builtins; dir(builtins)展示了这些。