简体   繁体   中英

How do I make the parameters parsed by configparser visible to every .py

I like to parse parameters, vars by using configparser. However, I have to pass the instance to every .py, in order to get the parameters.

What is the most elegant way to make the parameters visible to every .py ?

Thanks!

You could have "config" module, which parses the options into a global variable (in that same module) which you then include in all places where you need it.

Admittedly though, I do agree with delnan's comment, avoid globals if it's possible as in general it will push you to design better code. Personally I don't find them evil, as delnan says there are some cases where they still make sense.

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