r/Python • u/tc8219 • Apr 25 '21
Tutorial Stop hardcoding and start using config files instead, it takes very little effort with configparser
We all have a tendency to make assumptions and hardcode these assumptions in the code ("it's ok.. I'll get to it later"). What happens later? You move on to the next thing and the hardcode stays there forever. "It's ok, I'll document it.. " - yeah, right!
There's a great package called ConfigParser which you can use which simplifies creating config files (like the windows .ini files) so that it takes as much effort as hardcoding! You can get into the hang of using that instead and it should both help your code more scalable, AND help with making your code a bit more maintainble as well (it'll force you to have better config paramters names)
Here's a post I wrote about how to use configparser:
https://pythonhowtoprogram.com/how-to-use-configparser-for-configuration-files-in-python-3/
If you have other hacks about managing code maintenance, documentation.. please let me know! I'm always trying to learn better ways
17
u/IdiotCharizard Apr 25 '21
If I want to use third party libraries in sensitive work, I need to do a deep dive of the code to look for potential security threats, and keep it pinned. This makes dependencies a mess, and in a lot of cases it's just not worth using new ones when stdlib does enough.