- __dir__ is called when the built-in dir function is called on the module
- __getattr__ is called when an attribute is not found via the regular attribute lookup
Let's use this to build an environment based configuration module.
- Conviruation values has a value, environment key and a function to convert from str to right type
- I'm going to use dataclasses and populate values from environment in __post_init__
- Complex data types (such as list) should be JSON encoded in the environment variables
- All configuration values with start with the c_ prefix
- __dir__ will return a list configuration variables without the c_ prefix
- __getattr__ will add the c_ prefix and will look for the varialbes in globals
We're adding c_ prefix and removing it to bypass the regular attribute lookup mechanism. If we'll call a variable http_port and user will write config.http_port, our __dir__ function won't be called.
Here's the code
Thanks for sharing this Information. Python Course in Gurgaon
ReplyDeleteThis article is a great article, thank you for sharing with us Python
ReplyDeleteVery informative blog, thanks for the information.
ReplyDeleteDO check out Studytonight for more Python tutorials for future reference.
How to add two numbers entered by the user in #python | #bcaschool
ReplyDeleteHow to #add two #numbers in #python | #addition in #python | BCA School
Python is an interpreted high-level general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. Custom Web Design | SEO Company Pakistan
ReplyDeleteThank You for sharing python course
ReplyDeletePython Training in Noida
ReplyDeleteData Science Course in Chennai | Infycle Technologies
ReplyDeleteData science can be defined as a blend of Mathematics. The entire Data Life Cycle is covered in our Data Science course in Chennai, which includes Data Architecture, Statistics, Advanced Data Analytics, and Machine Learning. To enrol in this course, you must have a basic understanding of statistics and mathematics. We Infycle offer the Data Science course in Chennai with 200% practical classes, pre-mock interview sessions, and more career counseling classes. For a free demo session, call us at 7502633633.
Best python course in Chennai
Good article. Well-written and informative.
ReplyDeletePython Course Training at Hyderabad
If Big Data is a job that you're dreaming of, then we, Infycle are with you to make your dream into reality. Infycle Technologies offers the best Big Data Course Chennai, with various levels of highly demanded software courses such as Java, Python, Hadoop, AWS, etc., in 100% hands-on practical training with specialized tutors in the field. Along with that, the pre-interviews will be given for the candidates, so that, they can face the interviews with complete knowledge. To know more, dial 7502633633 for more.
ReplyDeleteBest software training in Chennai
This comment has been removed by the author.
ReplyDeletePython Course online
ReplyDeletePython online training
This comment has been removed by the author.
ReplyDelete