Python 3 locals() built-in function TUTORIAL

preview_player
Показать описание
Tutorial on how to use the locals() built-in function from the Python 3 Standard Library.

📖 Please check out my Udemy course here:

Documentation:

⚙️ Recommended Computer Gear:

✈️ Recommended Digital Nomad Gear:
Рекомендации по теме
Комментарии
Автор

locals can also be used to get ahold of classes by name to do targeted actions based on environment variables or other input arguments:
```
# script file
import os
class Demo:
def _get(self):
raise NotImplemented("need to get something")
class D_1(Demo):
def _get(self):
return True
def _do_other_stuff(self):
print("success")
class D_2(Demo):
""" this class will throw an exception for not implementing the _get function"""
def _set():
return True
if __name__ == "__main__":
desired_class =



# end script
```
where
d_value=D_1
or
d_value = D_2
i.e.
set d_value=D_1 (windows)
python3 <script file>.py
> success

maxsquires