Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python REPL中打印所有全局方法_Python_Read Eval Print Loop - Fatal编程技术网

在Python REPL中打印所有全局方法

在Python REPL中打印所有全局方法,python,read-eval-print-loop,Python,Read Eval Print Loop,Python中的REPL dir(str) 印刷品 ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len_

Python中的REPL

dir(str)
印刷品

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__',   '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
i、 e..string的所有可用方法


如何查看所有可用的全局方法,如“打印”、“列表”、“len”等?

请参阅以下模块:
Python2.7和Python3.x

例如:

In [32]: dir(__builtin__)
Out[32]: 
['ArithmeticError',
 'AssertionError',
 'AttributeError',
 'BaseException',
 'BufferError',
 'BytesWarning',
 'DeprecationWarning',
 'EOFError',
 'Ellipsis',
 'EnvironmentError',
 'Exception',
 'False',
 'FloatingPointError',
 'FutureWarning',
 'GeneratorExit',
 'IOError',
 'ImportError',
 'ImportWarning',
 'IndentationError',
 'IndexError',
 'KeyError',
 'KeyboardInterrupt',
 'LookupError',
 'MemoryError',
 'NameError',
 'None',
 'NotImplemented',
 'NotImplementedError',
 'OSError',
 'OverflowError',
 'PendingDeprecationWarning',
 'ReferenceError',
 'RuntimeError',
 'RuntimeWarning',
 'StandardError',
 'StopIteration',
 'SyntaxError',
 'SyntaxWarning',
 'SystemError',
 'SystemExit',
 'TabError',
 'True',
 'TypeError',
 'UnboundLocalError',
 'UnicodeDecodeError',
 'UnicodeEncodeError',
 'UnicodeError',
 'UnicodeTranslateError',
 'UnicodeWarning',
 'UserWarning',
 'ValueError',
 'Warning',
 'ZeroDivisionError',
 '__IPYTHON__',
 '__IPYTHON__active',
 '__debug__',
 '__doc__',
 '__import__',
 '__name__',
 '__package__',
 'abs',
 'all',
 'any',
 'apply',
 'basestring',
 'bin',
 'bool',
 'buffer',
 'bytearray',
 'bytes',
 'callable',
 'chr',
 'classmethod',
 'cmp',
 'coerce',
 'compile',
 'complex',
 'copyright',
 'credits',
 'delattr',
 'dict',
 'dir',
 'divmod',
 'dreload',
 'enumerate',
 'eval',
 'execfile',
 'file',
 'filter',
 'float',
 'format',
 'frozenset',
 'get_ipython',
 'getattr',
 'globals',
 'hasattr',
 'hash',
 'help',
 'hex',
 'id',
 'input',
 'int',
 'intern',
 'isinstance',
 'issubclass',
 'iter',
 'len',
 'license',
 'list',
 'locals',
 'long',
 'map',
 'max',
 'memoryview',
 'min',
 'next',
 'object',
 'oct',
 'open',
 'ord',
 'pow',
 'print',
 'property',
 'range',
 'raw_input',
 'reduce',
 'reload',
 'repr',
 'reversed',
 'round',
 'set',
 'setattr',
 'slice',
 'sorted',
 'staticmethod',
 'str',
 'sum',
 'super',
 'tuple',
 'type',
 'unichr',
 'unicode',
 'vars',
 'xrange',
 'zip']

正如@eryksun在他的评论中提到的,这将只在
\uuuuu main\uuuu
模块中起作用。如果要在导入的模块中执行此操作,请使用
sorted(\uuu builtins\uuu)

使用此命令可以获取所有内置函数


[x代表dir中的x(\uuu内置项)如果x.islower()而不是x.startswith(“\uuu')]

我可以问一下为什么需要这样做吗?@Volatility只是为了探索REPLi中可用的所有选项我正在获取名称错误:2.7中没有定义名称“内置项”。2@user1495306尝试
dir(\uuuu内置的)
dir(\uuu内置的)
\uuuuu主模块中,
\uuuuuu内置模块作为一个模块进行了特殊处理。在其他模块中,它是一个
dict
。在这种情况下,请使用
sorted(\uuuu内置项)
@Volatility-Good指出错误。使用未启动的(“”“”)进行编辑,该(“”)未命中
\uuuuu导入
。另外,3.x中的
\uuuuuuu构建\uuuu类
。排序(k表示k,v表示vars(uu内置)。items()如果可调用(v)和k.islower())
如何?
>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError',
 ...  # a whole bunch of other Errors
 'abs', 'all', 'any',
 ...  # other builtins
 'type', 'vars', 'zip']