Zanurkuj w Pythonie/Metody specjalne: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
tłumaczenie |
Nie podano opisu zmian |
||
Linia 38:
# Ta linia wygląda jak użycie słownika. Tylko, że <tt>f</tt> jest obiektem klasy próbującej udawać słownik a metoda <tt>__stitem__</tt> jest ważną częścią tej maskarady. Ta linia kodu powoduje właściwie wywołanie <tt>f.__setitem__("genre", 32)</tt>.
<tt>
This concept is the basis of the entire framework you're studying in this chapter. Each file type can have a handler class that knows how to get metadata from a particular type of file. Once some attributes (like the file's name and location) are known, the handler class knows how to derive other attributes automatically. This is done by overriding the __setitem__ method, checking for particular keys, and adding additional processing when they are found.
|