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

关于__init__.py 文件

  •  
  •   leisurelylicht · May 26, 2016 · 3664 views
    This topic created in 3624 days ago, the information mentioned may be changed or developed.
    __init__.py 文件应该是在包被导入的时候会自动调用,那可不可以把一些对包内模块的检查什么的放在__init__.py 中,如果检查出错就直接 assert ,停止整个程序。

    还是说__init__.py 里只能写模块导入,看网上大家的各种博客和文章也都只讲了模块导入的功能。
    6 replies    2016-05-27 17:15:50 +08:00
    JhZ7z587cYROBgVQ
        1
    JhZ7z587cYROBgVQ  
       May 26, 2016
    可以的啊
    czheo
        2
    czheo  
       May 27, 2016
    据说还有人在__init__.py 里写找不到包用 pip 自动安装的呢
    Mark24
        3
    Mark24  
       May 27, 2016
    可以的
    cwlmxwb
        4
    cwlmxwb  
       May 27, 2016 via iPhone
    测试一下就好了嘛
    ayaseangle
        5
    ayaseangle  
       May 27, 2016 via Android
    就是个普通文件而已,你没发现有些包虽然是个文件夹,但仅仅只有一个 initpy
    leisurelylicht
        6
    leisurelylicht  
    OP
       May 27, 2016
    @czheo 还可以这样的,这个我得试试
    @ayaseangle 原来如此,没仔细研究过其他包
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4547 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 10:04 · PVG 18:04 · LAX 03:04 · JFK 06:04
    ♥ Do have faith in what you're doing.