python isspace() 的完整实现在哪里?
Where is the complete implementation of python isspace()?
我试图覆盖 isspace()
的功能用于我的个人实验,因此我尝试导航到它的原始来源。我在以下实施中到达 builtins.py:
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
这让我很好奇这个内置函数在哪里实现,但无法弄清楚(可能是由于缺乏扎实的编程背景)。
我总是可以编写我的实现,但如果有人能指出这一点,那么在这个方向上多了解一点,以提高我对 python 的整体理解会很好。
有 Python 位用多种语言编写的口译员。这是原始的,其核心是用 C 语言编写的。它的一些库函数也是用 C 编写的。这是一个这样的功能。 isspace()
的任何地方都没有 Python 代码实现。要找到实现,您需要查看 C 代码。
更新:我刚看到@Amadan 的评论。我猜他找到了 C 代码。
更新 2:我有 CPython 代码,所以我自己看了看。我认为@Amadan 很接近,但我认为实际实现是 this C file
中的 unicode_isspace_impl
函数
我试图覆盖 isspace()
的功能用于我的个人实验,因此我尝试导航到它的原始来源。我在以下实施中到达 builtins.py:
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
这让我很好奇这个内置函数在哪里实现,但无法弄清楚(可能是由于缺乏扎实的编程背景)。
我总是可以编写我的实现,但如果有人能指出这一点,那么在这个方向上多了解一点,以提高我对 python 的整体理解会很好。
有 Python 位用多种语言编写的口译员。这是原始的,其核心是用 C 语言编写的。它的一些库函数也是用 C 编写的。这是一个这样的功能。 isspace()
的任何地方都没有 Python 代码实现。要找到实现,您需要查看 C 代码。
更新:我刚看到@Amadan 的评论。我猜他找到了 C 代码。
更新 2:我有 CPython 代码,所以我自己看了看。我认为@Amadan 很接近,但我认为实际实现是 this C file
中的unicode_isspace_impl
函数