Domanda

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.

È stato utile?

Soluzione

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   
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top