I'm fairly new to python, so this might be an obvious question, but I searched everywhere (including the documentation), and I can't seem to get the code object of a builtin function in python. For example, in my PyCharm editor, when I type this code, it does not detect any errors:
print(getattr.__code__)
But when I run it, it gives an AttributeError:
AttributeError: 'builtin_function_or_method' object has no attribute '__code__'
Is there a reason why built-in functions in python do not have a code object, and is this a bug in my IDE?
I am using Python 3.
Built-in functions don't have code objects because they're implemented in C, not in Python. Only Python functions have code objects, because code objects are compiled Python byte-code. Exploring Python Code Objects is a good explanation of code objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With