V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
ivito
V2EX  ›  Python

你们的__init__.py 都用来干啥呢

  •  
  •   ivito ·
    fireboyvt · Dec 15, 2015 · 4235 views
    This topic created in 3786 days ago, the information mentioned may be changed or developed.
    不同的代码中__init__.py 用法千差万别。
    有的人什么都不写,只为了告诉解释器这个文件夹是个 package
    有的人写一些变量的定义
    有的人把核心逻辑各种 class 定义都摆到这里

    那么问题来了,在日常的工作学习中你都用__init__.py 干点啥呢,符合规范吗?
    9 replies    2015-12-15 18:28:25 +08:00
    vanxining
        1
    vanxining  
       Dec 15, 2015 via Android
    更改、补充原生模块的接口。
    Damnever
        2
    Damnever  
       Dec 15, 2015
    http://docs.python-guide.org/en/latest/writing/structure/#packages 里面说最好不要写太多代码。。。

    像楼上说的,有时候也写点代码。。。 https://github.com/Damnever/Chat-Room/blob/master/handlers/__init__.py
    elvis_w
        3
    elvis_w  
       Dec 15, 2015
    既然是 init ,那就写这个 package 初始化的代码啊
    pynix
        4
    pynix  
       Dec 15, 2015
    一半是写 API 。。。
    gkiwi
        5
    gkiwi  
       Dec 15, 2015
    用来写 API
    fy
        6
    fy  
       Dec 15, 2015
    破事水呀,这东西没标准吧
    broven
        7
    broven  
       Dec 15, 2015
    写个作者,哈哈
    Feiox
        8
    Feiox  
       Dec 15, 2015
    写个版本,嘿嘿
    wenbinwu
        9
    wenbinwu  
       Dec 15, 2015
    __all__
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1065 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 18:48 · PVG 02:48 · LAX 11:48 · JFK 14:48
    ♥ Do have faith in what you're doing.