I need to write a function that imports a python script by absolute path. For example
my_path = "/my/path/to/python/script.py"
def import_script_by_absolute_path(path):
???
my_script = import_script_by_absolute_path(my_path)
print(my_script.my_sum(2, 2))
# prints 4
/my/path/to/python/script.py
contains:
def my_sum(a, b):
return a + b
UPD: Alternatively, you can suggest a function from a library that does it
UPD2: The question you lead to doesn't solve my problem. I need a function exactly and I can't understand how to do a function from the answers to this question