推荐学习书目
› 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
tanteng
V2EX  ›  Python

Python 项目的入口文件一般在哪?有什么通常做法?

  •  
  •   tanteng · May 8, 2015 · 4740 views
    This topic created in 4205 days ago, the information mentioned may be changed or developed.

    比如从网上下载的一个 python 项目,我都找不到哪个文件是主入口,一个 php 网站,通常 index.php 是入口文件,那么 python 呢?有什么通常做法?

    我是新手,谢谢回答!
    8 replies  •  2015-05-09 09:06:04 +08:00
    ca1n
    ca1n
    May 8, 2015
    1
    如果你说的是web的话,不同的框架有不同的入口,同样的框架也可以有不同的入口,比方说flask就可以调用script和不调用script调用的话入口是manage.py不调用的话是app.py这样,
    不过这些名字也并不是一成不变的名字而已都可以自己设定,如果你说的不是web的话那入口就各种各样了,有部分文件夹的入口是__init__.py,这都不是固定的

    拿你下载的这个项目来说的话你先看看文档,他正式运行的时候调用的是什么文件,那么他的入口就在那了,你跟着那个文件走就行了

    上面是我的理解,有说的不对的地方求指正 = =
    monkeylyf
    monkeylyf
    May 8, 2015
    2
    看个人风格和项目大小 我会放在.sh里
    你可以找类似optparser之类的库 或者哪里有执行main 或者if __name__ == '__main__':的地方 用grep试试吧
    wy315700
    wy315700
    May 8, 2015
    3
    wuyadong
    wuyadong
    May 8, 2015
    4
    要分项目类型来看。
    CodeDrift
    CodeDrift
    May 8, 2015
    5
    @wy315700 README.md +1 看说明嘛。。
    VYSE
    VYSE
    May 8, 2015
    6
    找没被function或class啥的包裹起来的代码就是入口
    loading
    loading
    May 9, 2015
    7
    居然给 github 截图而不是给地址,您找不到入口也是正常的。
    loading
    loading
    May 9, 2015
    8
    你应该是举例才发截图,但也差不多。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2356 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 11:37 · PVG 19:37 · LAX 03:37 · JFK 06:37
    ♥ Do have faith in what you're doing.