Config file with a .py file

前端 未结 4 495
南笙
南笙 2021-01-22 08:39

I have been told that doing this would be a not-very-good practice:

configfile.py

SOUNDENABLED = 1
FILEPATH = \'D:\\\\TEMP\\\\hello.txt\'
         


        
4条回答
  •  误落风尘
    2021-01-22 09:04

    The only concern here is that a .py can have arbitrary Python code, so it has a potential to break your program in arbitrary ways.

    If you can trust your users to use it responsibly, there's nothing wrong with this setup. If fact, at one of my previous occupations, we were doing just that, without any problems that I'm aware of. Just on the contrary: it allowed users to eliminate duplication by autogenerating repetitive parts and importing other config files.

    Another concern is if you have many files, the configuration ones are better be separated from regular code ones, so users know which files they are supposed to be able to edit (the above link addresses this, too).

提交回复
热议问题