Config file with a .py file

前端 未结 4 444
南笙
南笙 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:02

    Importing a module executes any code that it contains. Nothing restricts your configfile.py to containing only definitions. Down the line, this is a recipe for security concerns and obscure errors. Also, you are bound to Python's module search path for finding the configuration file. What if you want to place the configuration file somewhere else, or if there is a name conflict?

提交回复
热议问题