filmov
tv
HOW TO: A Python tutorial for dynamically importing or adding modules

Показать описание
In this video, we'll be using decorators and importlib to dynamically add modules to an application. This is a powerful trick when building frameworks that are then customised by some other module. However, it comes with an element of risk; you have to be careful about what folders you are importing from because there is always the possibility of a code injection attack.
----
Today we're going to use a combination of decorators and importlib to dynamically add modules to an application - we have a mockup of some kind of Bot like a discord or telegram bot, and this will receive messages.
If you're not in python, most languages do have this kind of dynamic loading and functionality, usually under a 'reflection' category, and this is a trick that is super powerful when building frameworks, that are then customised by some other module.
It also comes with an element of risk; you have to be careful about what folders you are importing from because there is always the possibility of a code injection attack, so importing dynamically is always a little bit risky. Hower utilised correctly, dynamic importing at run time does mean that you can add or remove modules between runs without modifying any root code or configs.
Python is a wonderful language to program in - yes it requires a bit more attention to your typing because it doesn't hold your hand in typos like some, but it has amazing flexibility and keeps its readability.
----
Today we're going to use a combination of decorators and importlib to dynamically add modules to an application - we have a mockup of some kind of Bot like a discord or telegram bot, and this will receive messages.
If you're not in python, most languages do have this kind of dynamic loading and functionality, usually under a 'reflection' category, and this is a trick that is super powerful when building frameworks, that are then customised by some other module.
It also comes with an element of risk; you have to be careful about what folders you are importing from because there is always the possibility of a code injection attack, so importing dynamically is always a little bit risky. Hower utilised correctly, dynamic importing at run time does mean that you can add or remove modules between runs without modifying any root code or configs.
Python is a wonderful language to program in - yes it requires a bit more attention to your typing because it doesn't hold your hand in typos like some, but it has amazing flexibility and keeps its readability.
Комментарии