ConfigParser vs. import config

前端 未结 4 957
北荒
北荒 2021-02-05 01:42

ConfigParser is the much debated vanilla configuration parser for Python.
However you can simply import config where config.py has python code whic

4条回答
  •  后悔当初
    2021-02-05 01:57

    IMO it comes down to a matter of personal style. Do you intend for 3rd parties to edit your config? If so, maybe it makes sense to have a more "natural" configuration style a la ConfigParser that is not as technical and that may not be too far over the heads of your target audience.

    Many popular projects such as Fabric and Django use the "native" configuration style which is essentially just a Python module. Fabry has fabfile.py and Django has settings.py.

    Overall, you're going to have a lot more flexibility using a native approach of importing a module simply because you can do anything you want in that file, including defining functions, classes, etc. because it's just another Python module you're importing.

提交回复
热议问题