Last active
January 10, 2017 05:46
-
-
Save idlesign/7482519 to your computer and use it in GitHub Desktop.
Теперь у нас есть метод на Костю Сапрыкина.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from types import MethodType | |
class Гражданин(): | |
"""Читайте, завидуйте: я — гражданин Советского Союза!""" | |
Глеб_Жеглов = Гражданин() | |
Костя_Сапрыкин = Гражданин() | |
# Теперь у нас есть метод против Кости Сапрыкина. | |
Глеб_Жеглов.метод = MethodType(lambda self, кому, куда, что: setattr(кому, куда, что), Глеб_Жеглов) | |
Глеб_Жеглов.метод(Костя_Сапрыкин, 'карман', ['кошелёк']) | |
print(Костя_Сапрыкин.карман) # ['кошелёк'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment