推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
jenrey
V2EX  ›  Python

有一个困惑:比如看 reversed 方法的源码里面的实现都是 pass,为什么会这样?如何才能看到源码呢?

  •  
  •   jenrey · Jun 25, 2022 · 3689 views
    This topic created in 1552 days ago, the information mentioned may be changed or developed.
    • pycharm2019
    • python3.9

    google 了一下,有人说因为底层是 C 实现,所以 pycharm 为了更好的体验帮我们隐藏了。 在此感谢每一位回复的前辈~

    3 replies  •  2022-06-28 09:22:21 +08:00
    westoy
        1
    westoy  
       Jun 25, 2022
    这和 python 基本没系啊,主要是 C 层面的

    这种 CPython 层面的东西, 你得先去 include 下面找头文件的定义

    比如这个

    https://github.com/python/cpython/blob/main/Include/listobject.h

    找到 PyList_Reverse

    然后就定位到 https://github.com/python/cpython/blob/main/Objects/listobject.c#L2606

    从里面再跳到上面的 static void reverse_slice(PyObject **lo, PyObject **hi)
    chenxytw
        2
    chenxytw  
       Jun 25, 2022   ❤️ 2
    不是 PyCharm 为了更好的体验隐藏了源码;是 PyCharm 为了更好的体验生成了 pyi 文件。
    因为 Python 大部分 builtin 都是 CPython 实现。标准库里面性能敏感的组件也是 CPython 实现。

    builtin 基本可以在这个文件找到 https://github.com/python/cpython/blob/main/Python/bltinmodule.c
    jenrey
        3
    jenrey  
    OP
       Jun 28, 2022
    @chenxytw @westoy 感谢前辈的回复,再一次深入的理解了 python 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2567 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 65ms · UTC 02:33 · PVG 10:33 · LAX 19:33 · JFK 22:33
    ♥ Do have faith in what you're doing.