gpt4 book ai didi

python - python isspace()的完整实现在哪里?

转载 作者:行者123 更新时间:2023-11-28 22:11:30 26 4
gpt4 key购买 nike

我试图为我的个人实验覆盖 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 函数。

关于python - python isspace()的完整实现在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55624636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com