If it won't be simple, it simply won't be. [Hire me, source code] by Miki Tebeka, CEO, 353Solutions

Thursday, March 05, 2020

Using __getattr__ for nicer configuration API

Typically, you'll read configuration from files (such as YAML) and get them as a dictionary. However in Python you'd like to write config.httpd.port and not config['httpd']['port']

__getattr__ is a hook method that's called by Python when regular attribute lookup fails (not to be confused with the lower level __getattribute__, which is much harder to work with). You can use it to wrap the configuration dictionary. Here's a small example.


4 comments:

Anonymous said...

It doesn't work for keys which have lists of dicts.

Rajendra Cholan said...

Data Science training in Chennai | Infycle Technologies

Infycle Technologies is the best software training center in Chennai, providing amazing Data Science training in Chennai which will be realistic and taught by industry experts. Aside from practical training preparation, mock interviews will be arranged for students so that they can confidently face the interviews. All of this will be packed up by full placement assurance with the best salary package from top companies. For having a free demo session, call 7502633633.

best software training in Chennai

Rajendra Cholan said...

Learn Big Data for making your career towards a sky-high with Infycle Technologies. Infycle Technologies is the best Big Data training institute, providing courses for the Big Data certification in Chennai in 200% hands-on practical training with professional trainers in the domain. Apart from the training, the placement interviews will be arranged for the students, so that they can set their career without any struggle. Of all that, 100% placement assurance will be given here. To have the best career, call 7502633633 to Infycle Technologies and grab a free demo to know more.
Best software training in Chennai

Jack Dowson said...

With the assistance of DeFi advancement administrations, organizations can assemble decentralized, blockchain-based monetary frameworks, as Solana programming improvement. Whenever executed, these advancements can possibly work on regular monetary frameworks with regards to transparency, security, and efficiency.

Brilliant agreements likewise empower firms to dispose of the requirement for go betweens in monetary exchanges via mechanizing them. Organizations that put resources into DeFi advancement administrations approach the engineers and clients who are molding the fate of the DeFi business.

In total, by using administrations, for instance, on-request DeFi wallet improvement, organizations might expect market moves and produce imaginative monetary arrangements proper for the quickly advancing computerized economy>> defi development company

Blog Archive