I have came up with this:
[a for a in dir(__builtins__) if str(type(getattr(__builtins__,a))) == "<type 'builtin_function_or_method'>"]
I know its ugly. Can you show me a better/more pythonic way of doing this?
I have came up with this:
[a for a in dir(__builtins__) if str(type(getattr(__builtins__,a))) == "<type 'builtin_function_or_method'>"]
I know its ugly. Can you show me a better/more pythonic way of doing this?
There is the inspect
module:
import inspect
filter(inspect.isbuiltin, (member for name, member in inspect.getmembers(__builtins__)))
Edit: reading the documentation a little more closely, I came up with this variant that doesn't use __getattr__
import inspect
members = (member for name, member in inspect.getmembers(__builtins__))
filter(inspect.isbuiltin, members)
Here's a variation without getattr:
import inspect
[n.__name__ for n in __builtins__.__dict__.values() if inspect.isbuiltin(n)]
And if you want the actual function pointers:
import inspect
[n for n in __builtins__.__dict__.values() if inspect.isbuiltin(n)]