V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
polythene
1D
V2EX  ›  程序员

问一个关于配置文件的最佳实践

  •  
  •   polythene ·
    polyrabbit · Jul 2, 2013 · 3408 views
    This topic created in 4686 days ago, the information mentioned may be changed or developed.
    不知道大家是喜欢在主模块里把配置文件解析好,然后用参数的形式传递给各子模块呢,还是在各子模块里单独解析配置文件(当然有专门的config.py解析文本形式的配置文件XXX.cfg)?

    在主模块里解析会使得主模块看起来很臃肿,而在子模块里解析又让我觉得子模块对外的依赖太多了,不知道哪一种更合适些??
    谢谢~~
    5 replies    1970-01-01 08:00:00 +08:00
    polythene
        1
    polythene  
    OP
       Jul 2, 2013
    消灭零回复
    sykp241095
        2
    sykp241095  
       Jul 2, 2013   ❤️ 1
    通常情况,我会在utils.py里def load_config()得到一个大的配置数据结构。

    然后在main.py里from utils import load_config ,再传给子模块。
    polythene
        3
    polythene  
    OP
       Jul 2, 2013
    @sykp241095 多谢分享
    vibbow
        4
    vibbow  
       Jul 2, 2013   ❤️ 1
    我在PHP里,配置文件是直接存在一个ini文件里
    然后php用parse_ini_file去读,再存到全局变量里...
    polythene
        5
    polythene  
    OP
       Jul 3, 2013
    @vibbow 那这就类似于在子模块里读取配置文件了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   847 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:05 · PVG 06:05 · LAX 15:05 · JFK 18:05
    ♥ Do have faith in what you're doing.