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
wecan
V2EX  ›  Python

Python 中的_run_init 函数也是在实例创建时自动执行的吗?和__init__有什么区别

  •  
  •   wecan · 2018-01-17 19:28:33 +08:00 · 2756 次点击
    这是一个创建于 2262 天前的主题,其中的信息可能已经有所发展或是发生改变。
    例如下面的代码当中有一个__run_init:

    4 条回复    2018-01-18 09:06:17 +08:00
    xpresslink
        1
    xpresslink  
       2018-01-17 22:07:04 +08:00   ❤️ 1
    _run_init 这个写法只是普通方法,不会自动执行。
    beforeuwait
        2
    beforeuwait  
       2018-01-17 22:41:06 +08:00
    这我还真不知道
    ipwx
        3
    ipwx  
       2018-01-17 23:31:44 +08:00 via Android   ❤️ 1
    看看基类是不是重载了 __new__ 或者有 metaclass
    XIVN1987
        4
    XIVN1987  
       2018-01-18 09:06:17 +08:00   ❤️ 1
    是_run_init,不是__run_init

    首尾各有两个下划线的是 magic method,有特殊用途的,在特定条件下自动调用,,比如__init__、__str__、__repr__、__eq__等

    一个下划线一般表示 private 变量、方法,当然,它并没有真的变成 private,只是一种社区的约定俗成,,
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1614 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:52 · PVG 00:52 · LAX 09:52 · JFK 12:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.