简体   繁体   中英

Pass variables to development.ini on Pyramid

Using Pyramid + MySQL (sqlalchemy), I have the development.ini file and since I'm working with a team, everyone needs different database url on development.ini. Is there anyway to pass variables to development.ini files:

Something like this:

myconfig.py

DB_USER = 'user'
DB_PASSWORD = 'pass'
DB_DATABASE = 'db_name'
DB_HOSTNAME = 'localhost'

development.ini

sqlalchemy.url = mysql://DB_USER:DB_PASSWORD@DB_HOSTNAME/DB_DATABASE

That way, every developer can have a non-versioned myconfig.py.

Sounds kinda complicated - import variables from Python into an .ini file only to load that file back into Python :)

How about that:

try:
    from .myconfig import DB_STRING
    engine = sa.create_engine(DB_STRING, echo=False)
except ImportError:
    # ... no myconfig.py found - proceed to configuring the engine from .ini file   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM