Skip to main content
Update to a better method
Source Link
Ben Beirut
  • 763
  • 3
  • 13

What you suggested seems good to me.

builtin = dir(__builtins__)
def is_builtin(tested_object):
    return tested_object.__class__.__name__ in builtin

Bear in mind, however, that built-in types can be overshadowed.

Update after comment from Rob:

def is_builtin(tested_object):
    return tested_object.__class__.__module__ == '__builtin__'

What you suggested seems good to me.

builtin = dir(__builtins__)
def is_builtin(tested_object):
    return tested_object.__class__.__name__ in builtin

Bear in mind, however, that built-in types can be overshadowed.

What you suggested seems good to me.

builtin = dir(__builtins__)
def is_builtin(tested_object):
    return tested_object.__class__.__name__ in builtin

Bear in mind, however, that built-in types can be overshadowed.

Update after comment from Rob:

def is_builtin(tested_object):
    return tested_object.__class__.__module__ == '__builtin__'
Source Link
Ben Beirut
  • 763
  • 3
  • 13

What you suggested seems good to me.

builtin = dir(__builtins__)
def is_builtin(tested_object):
    return tested_object.__class__.__name__ in builtin

Bear in mind, however, that built-in types can be overshadowed.