THIS Feels Incredibly WRONG In Python, They Call It: "Monkey Patching"

  Рет қаралды 13,296

Indently

Indently

Жыл бұрын

Yes, you read it correctly. In this video I will be showing you a concept which they call "monkey patching" in Python. As crazy as it sounds, it does have some interesting usages!
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels

Пікірлер: 34
@Migoyan
@Migoyan Жыл бұрын
This is possible because function are objects in python. In C the closest thing are function pointers (which is what does python under the hood).
@AWriterWandering
@AWriterWandering Жыл бұрын
It occurs to me that this is the closest thing Python has to externally defined methods in languages like C++.
@cerealport2726
@cerealport2726 Жыл бұрын
I really thought monkey patching might be the practice of senior developers throwing excrement over the code written by junior developers...
@zapp7746
@zapp7746 Жыл бұрын
Zapp here, and I was the first person here, remember me
@Kommentierer
@Kommentierer Жыл бұрын
Feels like shooting with pointers like a C-guy.
@godowskygodowsky1155
@godowskygodowsky1155 14 күн бұрын
Mocking is better. Use dependency injection and a strategy pattern.
@mage1over137
@mage1over137 Жыл бұрын
So because in python modules are objects, and all you need for a module is a file, I have this way of building simple utility scripts that evolve as the complexity grows. I use this technique to create sub class without making a class. At some point everything gets refractored into a class. But it's really a nice way to build a project from scratch.
@grahampawar
@grahampawar Жыл бұрын
Very informative! 😄👍
@Kevinschart
@Kevinschart Жыл бұрын
i just implemented monkey patching without realizing it had a name. SUPER useful!
@linux2420
@linux2420 Жыл бұрын
This is terrifying and i love it
@rje4242
@rje4242
in python you can effortlessly redefine any function, even built in ones, which is a terrific way to trip yourself up:
@expertcynos2123
@expertcynos2123
more interested in you linking out your hoodie please, thats cool af
@dcknature
@dcknature Жыл бұрын
I really don't care how it feels in Python, as long as it's useful 👌.
@Gruuvin1
@Gruuvin1 Жыл бұрын
Where I work, we often have to modify production code, and and restart the production process, which is what we call monkey patching. This is going around the usual process of modifying in a development environment, test, build and release to production (install a proper upgrade).
@lukerichards22
@lukerichards22 Жыл бұрын
I did something like this once when I wanted to debug by reading all of the print statements on a script that outputted a LOT of print statements. I just changed the print function to one that wrote the repr string to a file instead. Did the job.
@zangdaarrmortpartout
@zangdaarrmortpartout Жыл бұрын
When testing you should use mocks, it's basically monkey patching with more functionality, less bloat code, and also cleaner
@nordgaren2358
@nordgaren2358 Жыл бұрын
You know you can use this to add to the function by saving the function in a variable, first, and then calling it inside the patched function? It looks a bit weird, but that's kind useful. Allows you to either change the imput before calling the original function, or change the output after calling it!
@GooogleGoglee
@GooogleGoglee Жыл бұрын
@
@budweiser1243
@budweiser1243 Жыл бұрын
Hey Indently I have a problem, when I was making my discord bot on python I finished but I didnt get the same thing as you I got "process finished with exit code 0" what do I do?
@alidev425
@alidev425 Жыл бұрын
Thanks for the video
+10 CRAZY Ways To FORMAT Text In Python with F-Strings
9:15
Indently
Рет қаралды 20 М.
Learn Python's AsyncIO in 15 minutes
14:02
Indently
Рет қаралды 50 М.
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,8 МЛН
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Гараж 54
Рет қаралды 14 МЛН
5 Tips To Write Better Python Functions
15:59
Indently
Рет қаралды 97 М.
Unit testing using monkey patching in pytest - Vikram Bhat
29:12
How To FIND SLOW CODE In Python & OPTIMIZE IT (FT. cProfile)
9:23
How To Write Unit Tests For Existing Python Code // Part 1 of 2
25:07
WHAT Is "Pickle" In Python?! (EXTREMELY Useful!)
9:32
Indently
Рет қаралды 76 М.
THIS Is How You Should Be Making Getters & Setters In Python
7:32
CONTEXT MANAGERS In Python Are GENIUS!
4:49
Indently
Рет қаралды 26 М.
ALL 47 STRING METHODS IN PYTHON EXPLAINED
23:34
Indently
Рет қаралды 121 М.
5 Really Cool Python Functions
19:58
Indently
Рет қаралды 56 М.