Magic Methods in Python -


After

I am doing something new to Python and I wonder if something like Magic Methods in PHP If there is a way)

My goal is to reduce the reach of child organs in my model. I basically have a parental class in which there are n child classes, these classes have three values, one language key, one translation key and one translation value. They are describing the handling of a general translation. There may be translations of the original class for each translation key in different languages ​​such as the key "title" can be translated into German and English and the key "description" also (and so far and so on)

< P> I do not want to receive the hair sections and want to filter by set values ​​(at least I want but not clearly, the solid implementation of the magic method will do this) I want to call They are

  parent_class.title ["day"] # or even parent_class.title ('D')  

to get translations For the title in German (D)

Therefore there should be a magic method that takes the name of the named method and their parameters (as in PHP). As far as getting directly inside these simple features (__getattr__, __setattr__) or setting in my Python / square (__getitem__, __setitem__) which both do not fit my needs.

Maybe there is a solution for this with possible? Please help! thank you in advanced!

"itemprop =" text ">

which is a return an object for parent_class.title __ GetItem __ Method.

  class parent_class: def __init __ (self): self.title = multilang ("hello world"); Class multilang: def __init __ (self, text): pass def __getitem __ (self, key): if key == 'n': return "hello world";  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -