Giter VIP home page Giter VIP logo

jolla's Issues

我来讨论一下 __init__.py 的内容吧

init.py 一般有三种作用,除了标记 module 外,还能:
① 留空
② 在 init.py 中引入所有的模块。import all modules
③ 在 init.py 中引入 key function 到 package namespace。好处在于当你重构了整个代码之后仍然有办法使得 API 保持稳定。(在 reddit 里的一个讨论帖里所提到的)

实际上我最喜欢的是第②和第③种,可以简化引入的模块。

所以从这点来看的话,在 init.py 里:
① 不用 import *,只要第一行就够了
② 用 from .server import WebApp 来替代 from server import WebApp。前者是 explicit relative import,后者是 implicit relative import。虽然在同一个 module 里两种都是没有问题的,但 Pythonic~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.