Aug-07-2018, 08:50 PM
Python documentation lists 69 built-in functions (compared to 3.6 there is one new built-in function in 3.7 (breakpoint()).
How do I get this exact same list of built-in functions in interactive interpreter?
One can try __builtins__:
One can try filter __builtin__.__dict__ values:
There is types module, but in types.BuiltinFunctionType the term “built-in” means “written in C”
There is inspect module and inspect.isbuiltin(object) which will return true if the object is a built-in function or a bound built-in method. However, it will give same result as with builtins dict:
How do I get this exact same list of built-in functions in interactive interpreter?
One can try __builtins__:
>>> dir(__builtins__)[80:] ['abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']This is very close, however it will give 'copyright', 'credits', 'license' which are not listed in documentation and misses
__import__()
.One can try filter __builtin__.__dict__ values:
>>> for key, value in __builtins__.__dict__.items(): ... if 'built-in function' in repr(value): ... print(key, end=',') ... __build_class__,__import__,abs,all,any,ascii,bin,breakpoint,callable,chr, compile,delattr,dir,divmod,eval,exec,format,getattr,globals,hasattr,hash, hex,id,input,isinstance,issubclass,iter,len,locals,max,min,next,oct,ord,pow, print,repr,round,setattr,sorted,sum,vars,open,>>>This misses several built-in functions which has values as class (for example: ''memoryview': <class 'memoryview'>, 'bytearray': <class 'bytearray'>, 'bytes': <class 'bytes'>, 'classmethod': <class 'classmethod'>, 'complex': <class 'complex'> etc). Modifying condition to include keys which values contain 'class' will bring also all errors, KeyboardInterrupt etc.
There is types module, but in types.BuiltinFunctionType the term “built-in” means “written in C”
There is inspect module and inspect.isbuiltin(object) which will return true if the object is a built-in function or a bound built-in method. However, it will give same result as with builtins dict:
>>> import inspect >>> for item in dir(__builtins__): ... if inspect.isbuiltin(eval(item)): ... print(item, end=',') ... __build_class__,__import__,abs,all,any,ascii,bin,breakpoint,callable,chr, compile,delattr,dir,divmod,eval,exec,format,getattr,globals,hasattr,hash, hex,id,input,isinstance,issubclass,iter,len,locals,max,min,next,oct,open,ord,pow, print,repr,round,setattr,sorted,sum,vars,>>>So - is there pythonic way do get all and only 69 functions listed in documentation from interactive interprpeter?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.