 My module of the month this month is config bar sir, all right. Oh, uh, well the pros in the room It's in lowercase in python 3 and python 2 is it was configured capital C and p of capital p right, so Who here knows what an any file is? right Kind of let me just type one out Let me print you right so any file basically is Uh, you have what's called sections every section header is between these square brackets here And then in each section you'll have variables with a value. Okay, so separated by an equal or a colon So in this case, I have two sections one called db one called app I don't know. Maybe i'm trying to configure a web app in my db. I'll have a variable called host variable called port App add this little comment. So this comment is just for me It's not read in the configuration file It's ignored by most part by the good parsers and it's just for my edification right and Then a variable right so Any files is Basically go figure a way to store configuration as opposed to a lot of people would say use jason Some people others might use xml The glory and the the the benefit of any files is that they're very very simple to write out To and to use and arguably compared to say Jason you can put comments in it. Yeah, and the parsing is a bit friendlier A bit less error pro But uh, let's see how we can use any files in python. So I import config parser Little cheat sheet So I don't I don't type these from memory. I have to read them from a sheet So I create what's called a config Create my config parser object by calling it So I'm just going to call it config and config is going to read a configuration. So here it's going to read string This is the any file as a string that I typed out earlier and suddenly I have a config with all the sections I had in my any file And I can list the keys In that section so my db. I wound up my host and my port and finally I can get to that So in this case it has a key host and port Um, I want username username is not there So I'm going to give it a default value and like a regular python dictionary using the get method It will turn me my default value right, uh, do note that Uh, the very uh, everything's a string right. So this is a dictionary strings and config files So exactly my port is now a string if I want to use it in a configure in my in my database library And indeed it is an int. I'll have to cast it myself right you only get strings and also gloriously, it is also not Case sensitive, you know keep things easy Uh, so for example my admin email on lowercase as opposed to my actual variable Which is admin with a capital a capital a still pick up The thing so make sure you don't have two variables that are the same if you lowercase them and all that But other than that, you know, keep it easy keep it simple keep in 1980s and Also also works as the uppercase both will match to the same variable um What's good about config parsers? Let's say I have another configuration, right? So here I have Let me print this out for you So I have a section called dv like I had above and I have another variable port now this time 6 4 3 2 not the 5 4 3 2 well in my config I just read it again and it'll update the proper section. So if I try to get my port You'll get my new value again the string, but I still have access to all the old values I had in my previous config file, right? Um, why would this be useful? Well, let me write out these these these configuration files to file to through disk, right? So this is my main and let's say I call the other one Local right Well, one really really cool method is config. I call in you. So I created an empty one And config dot read right and to read I pass a list Of files, right? So in this case, I have main which I just wrote local Which I just also wrote and say testing testing doesn't exist But it might be there might be there on certain servers that I have it might be on my ci server, right? I call that it'll tell me. Oh, these are the any files. I found Oh, you passed one. I didn't find I didn't raise an error. I just ignored it No, uh, no pressure and I'll give you The the I'll give you the variables from uh, the sorry I'll first of all load all the variables from this one and then overwrite all the ones that I find in this one So it found this db host from the first one And it finds the port from the second one and you're none the wiser So you can layer on configuration files. So maybe you have like a main one and then you'll have Uh, a local configuration for local development or your testing or integration server might have a different Configuration you can layer those with these and don't have to worry. Oh, do I have to copy on everyone? Am I missing this variable and keep it simple like that and that's basically it