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

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

  •  
  •   ivito ·
    fireboyvt · 2015-12-15 13:49:22 +08:00 · 3537 次点击
    这是一个创建于 3054 天前的主题,其中的信息可能已经有所发展或是发生改变。
    不同的代码中__init__.py 用法千差万别。
    有的人什么都不写,只为了告诉解释器这个文件夹是个 package
    有的人写一些变量的定义
    有的人把核心逻辑各种 class 定义都摆到这里

    那么问题来了,在日常的工作学习中你都用__init__.py 干点啥呢,符合规范吗?
    9 条回复    2015-12-15 18:28:25 +08:00
    vanxining
        1
    vanxining  
       2015-12-15 14:02:35 +08:00 via Android
    更改、补充原生模块的接口。
    Damnever
        2
    Damnever  
       2015-12-15 14:30:13 +08:00
    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  
       2015-12-15 15:47:36 +08:00
    既然是 init ,那就写这个 package 初始化的代码啊
    pynix
        4
    pynix  
       2015-12-15 15:52:56 +08:00
    一半是写 API 。。。
    gkiwi
        5
    gkiwi  
       2015-12-15 16:03:07 +08:00
    用来写 API
    fy
        6
    fy  
       2015-12-15 16:51:23 +08:00
    破事水呀,这东西没标准吧
    broven
        7
    broven  
       2015-12-15 18:17:08 +08:00
    写个作者,哈哈
    Feiox
        8
    Feiox  
       2015-12-15 18:24:37 +08:00
    写个版本,嘿嘿
    wenbinwu
        9
    wenbinwu  
       2015-12-15 18:28:25 +08:00
    __all__
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1594 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:03 · PVG 01:03 · LAX 10:03 · JFK 13:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.