有一个困惑:比如看 reversed 方法的源码里面的实现都是 pass,为什么会这样?如何才能看到源码呢? - V2EX
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 3040 次点击
    这是一个创建于 1250 天前的主题,其中的信息可能已经有所发展或是发生改变。
    • 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     Solana     5301 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 35ms UTC 07:01 PVG 15:01 LAX 23:01 JFK 02:01
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86