Where is the complete implementation of python isspace()?

℡╲_俬逩灬. 提交于 2020-04-13 16:51:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!