问题
I was trying to override the functionality of isspace()
for my personal experiments, so I tried to navigate to the origin source of it. I landed up at builtins.py at the following implementation:
def isspace(self): # real signature unknown; restored from __doc__
"""
S.isspace() -> bool
Return True if all characters in S are whitespace
and there is at least one character in S, False otherwise.
"""
return False
This made me curious as to where is this builtin implemented but couldn't figure this one out (maybe due to lack of solid programming background).
I can always write my implementations but it would be good to know bit more in this direction, to improve my overall understanding of python, if someone could point this out.
回答1:
There are Python interpreters written in a number of languages. This, the original, is written in C at its core. Some of its library function are written in C as well. This is one such function. There is no Python code implementation of isspace()
anywhere. To find the implementation, you'd need to look at the C code.
UPDATE: I just saw @Amadan's comment. I guess he's found the C code.
UPDATE2: I had the CPython code lying around, so I looked myself. I think @Amadan was close, but I think the actual implementation is the unicode_isspace_impl
function in this C file
来源:https://stackoverflow.com/questions/55624636/where-is-the-complete-implementation-of-python-isspace