python - Ce qui est init__.py pour

Mots clés : pythonmodulepackagepython-packagingpython

meilleur 3 Réponses python - Ce qui est init__.py pour

vote vote

90

mydir/spam/__init__.py mydir/spam/module.py 
import spam.module 
from spam import module 
import spam 
vote vote

84

database/     __init__.py     schema.py     insertions.py     queries.py 
import os  from sqlalchemy.orm import sessionmaker from sqlalchemy import create_engine  engine = create_engine(os.environ['DATABASE_URL']) Session = sessionmaker(bind=engine) 
from database import Session session = Session() 
from database.create_session import Session session = Session() 
vote vote

75

your_package/   __init__.py   file1.py   file2.py     ...   fileN.py 
# in __init__.py from file1 import * from file2 import * ... from fileN import * 
# in file1.py def add():     pass 
 from your_package import add 
 from your_package.file1 import add 
 import logging.config  logging.config.dictConfig(Your_logging_config) 

Questions similaires