? Python | Console Application: Converting functions to routines using decorators ??♻⏰??
Playing with Python decorators to convert functions to routines.
The decorator can be called or not, if not called, it will autostart by default.
If it's called with True, it will autostart. With False, it won't autostart and the function will have to be called manually.
The decorator uses the "wrapper function" concept.
The routine is a simple class, witih an isActive boolean property,
and start/stop methods.
The start method runs the callback function (the function that we want to convert to a routine) inside a while loop and the loop will run until the isActive property is set to False.
The stop methods just sets the isActive property to False to stop the while loop.
It looks scary and difficult at first, but decorators are amazing, easy and fun!
TypeScript and JavaScript programming languages also count with decorators (JavaScript needs the Babel transpiler though).
In the future, I will add plugins for the Routine class,
like a Time plugin with the wait(seconds) method,
an Input class to show inputs, prompts, etc., a System plugin with methods to manipulate the system (using sys and os packages) like the os.system('cls') we used in this video to clear the console.
Plugins will be dictionaries or class instances with an install method,
which return either a function or an instance of a class, to inject
in the Routine class as an instance property,
and being able to use them in the routines via the routine parameter.
Will also add the previous routine as an extra parameter
so that it can be stopped in a subroutine.
Have a suggestion for this project?
Have a suggestion for a new video?
Have a question about any previous video?
Please, let me know in the comments!
[ Timestamps ]
00:00:00 Intro
00:00:13 Skip Intro
00:14:18 Outro
console.log("Have fun!") ?✌
[ Relaxing Ambient Sounds ]
https://www.youtube.com/c/therelaxedguy
[ Editor/IDE ]
https://code.visualstudio.com/
[ My VSCode Extensions ]
https://github.com/angelhdzmultimedia/vscode-extensions
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «? Python | Console Application: Converting functions to routines using decorators ??♻⏰??», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.