Why are some functions omitted in `dir()` output?

Viewed 95

In the Python console started by PyCharm, it looks like runfile is an imported function:

In[21]: runfile
Out[21]: <function _pydev_bundle.pydev_umd.runfile(filename, args=None, wdir=None, is_module=False, global_vars=None)>

Since it's a name in the local scope, shouldn't it be listed in dir()'s output?

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']
1 Answers

Good question. Because runfile is made as a built-in, just like dir() itself.

If dir() without argument can list all available calls, it should list itself too...

Python shell will search for the name not only in local scope, but also in built-in module.

You can find both dir and runfile in dir(__builtin__).

Related