V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2022-06-25 11:22:51 +08:00 · 2428 次点击
    这是一个创建于 668 天前的主题,其中的信息可能已经有所发展或是发生改变。
    • pycharm2019
    • python3.9

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

    3 条回复    2022-06-28 09:22:21 +08:00
    westoy
        1
    westoy  
       2022-06-25 11:50:01 +08:00
    这和 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  
       2022-06-25 18:19:58 +08:00   ❤️ 2
    不是 PyCharm 为了更好的体验隐藏了源码;是 PyCharm 为了更好的体验生成了 pyi 文件。
    因为 Python 大部分 builtin 都是 CPython 实现。标准库里面性能敏感的组件也是 CPython 实现。

    builtin 基本可以在这个文件找到 https://github.com/python/cpython/blob/main/Python/bltinmodule.c
    jenrey
        3
    jenrey  
    OP
       2022-06-28 09:22:21 +08:00
    @chenxytw @westoy 感谢前辈的回复,再一次深入的理解了 python 。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   986 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:55 · PVG 05:55 · LAX 14:55 · JFK 17:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.