推荐学习书目
› 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 · Jan 17, 2018 · 3458 views
    This topic created in 3177 days ago, the information mentioned may be changed or developed.
    例如下面的代码当中有一个__run_init:

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

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

    一个下划线一般表示 private 变量、方法,当然,它并没有真的变成 private,只是一种社区的约定俗成,,
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   943 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 19:16 · PVG 03:16 · LAX 12:16 · JFK 15:16
    ♥ Do have faith in what you're doing.