PYTHONL Telegram 5121
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ”₯ Python Ρ‚Ρ€ΡŽΠΊ: динамичСскоС Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² Π² класс

Мало ΠΊΡ‚ΠΎ Π·Π½Π°Π΅Ρ‚, Π½ΠΎ Π² Python ΠΌΠΎΠΆΠ½ΠΎ Π½Π° Π»Π΅Ρ‚Ρƒ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π² ΡƒΠΆΠ΅ созданный класс. Π­Ρ‚ΠΎ ΡƒΠ΄ΠΎΠ±Π½ΠΎ для ΠΏΠ»Π°Π³ΠΈΠ½ΠΎΠ², тСстов ΠΈΠ»ΠΈ динамичСских API.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ πŸ‘‡


class User:
def __init__(self, name):
self.name = name

# ΠžΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚
u = User("Alice")

# Ѐункция, ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ Ρ…ΠΎΡ‚ΠΈΠΌ "ΠΏΠΎΠ΄ΠΌΠ΅ΡˆΠ°Ρ‚ΡŒ"
def greet(self):
return f"Hello, {self.name}!"

# Π’ΠΊΠ»ΠΈΠ½ΠΈΠ²Π°Π΅ΠΌ ΠΌΠ΅Ρ‚ΠΎΠ΄ Π² класс
User.greet = greet

print(u.greet()) # Hello, Alice!


⚑ ΠŸΡ€ΠΈΡ‘ΠΌ называСтся monkey patching.

Π­Ρ‚ΠΎ ΠΌΠΎΡ‰Π½Ρ‹ΠΉ инструмСнт β€” Π½ΠΎ ΠΈΠΌ Π½Π°Π΄ΠΎ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π°ΠΊΠΊΡƒΡ€Π°Ρ‚Π½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ ΡΠ»ΠΎΠΌΠ°Ρ‚ΡŒ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΠΎΡΡ‚ΡŒ ΠΊΠΎΠ΄Π°.

https://www.youtube.com/shorts/64-dqXJZ8RM
πŸ”₯24😱11❀7πŸ‘5😁1



tgoop.com/pythonl/5121
Create:
Last Update:

πŸ”₯ Python Ρ‚Ρ€ΡŽΠΊ: динамичСскоС Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΌΠ΅Ρ‚ΠΎΠ΄ΠΎΠ² Π² класс

Мало ΠΊΡ‚ΠΎ Π·Π½Π°Π΅Ρ‚, Π½ΠΎ Π² Python ΠΌΠΎΠΆΠ½ΠΎ Π½Π° Π»Π΅Ρ‚Ρƒ Π΄ΠΎΠ±Π°Π²Π»ΡΡ‚ΡŒ ΠΌΠ΅Ρ‚ΠΎΠ΄Ρ‹ Π² ΡƒΠΆΠ΅ созданный класс. Π­Ρ‚ΠΎ ΡƒΠ΄ΠΎΠ±Π½ΠΎ для ΠΏΠ»Π°Π³ΠΈΠ½ΠΎΠ², тСстов ΠΈΠ»ΠΈ динамичСских API.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ πŸ‘‡


class User:
def __init__(self, name):
self.name = name

# ΠžΠ±Ρ‹Ρ‡Π½Ρ‹ΠΉ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚
u = User("Alice")

# Ѐункция, ΠΊΠΎΡ‚ΠΎΡ€ΡƒΡŽ Ρ…ΠΎΡ‚ΠΈΠΌ "ΠΏΠΎΠ΄ΠΌΠ΅ΡˆΠ°Ρ‚ΡŒ"
def greet(self):
return f"Hello, {self.name}!"

# Π’ΠΊΠ»ΠΈΠ½ΠΈΠ²Π°Π΅ΠΌ ΠΌΠ΅Ρ‚ΠΎΠ΄ Π² класс
User.greet = greet

print(u.greet()) # Hello, Alice!


⚑ ΠŸΡ€ΠΈΡ‘ΠΌ называСтся monkey patching.

Π­Ρ‚ΠΎ ΠΌΠΎΡ‰Π½Ρ‹ΠΉ инструмСнт β€” Π½ΠΎ ΠΈΠΌ Π½Π°Π΄ΠΎ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π°ΠΊΠΊΡƒΡ€Π°Ρ‚Π½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ ΡΠ»ΠΎΠΌΠ°Ρ‚ΡŒ Ρ‡ΠΈΡ‚Π°Π΅ΠΌΠΎΡΡ‚ΡŒ ΠΊΠΎΠ΄Π°.

https://www.youtube.com/shorts/64-dqXJZ8RM

BY Python/ django


Share with your friend now:
tgoop.com/pythonl/5121

View MORE
Open in Telegram


Telegram News

Date: |

On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of β€œdoxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. According to media reports, the privacy watchdog was considering β€œblacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. The administrator of a telegram group, "Suck Channel," was sentenced to six years and six months in prison for seven counts of incitement yesterday.
from us


Telegram Python/ django
FROM American