I have two files /somewhere/main.py and /somewhere/repeated_name.py and then I have other file /random/path/repeated_name.py. How do I import a function from /random/path/repeated_name.py into /somewhere/main.py?
I have two files /somewhere/main.py and /somewhere/repeated_name.py and then I have other file /random/path/repeated_name.py. How do I import a function from /random/path/repeated_name.py into /somewhere/main.py?
I think you can use shutil for that. All you need is the absolute path and then use the shutil.move(src, dst) method. And then you just have to use the from file import method without bothering about the folder.
But if you want to import a function to another file, I think this article should answer your question: https://www.geeksforgeeks.org/python-import-module-from-different-directory/
You can use:
from somewhere.repeated_name import func_name
Just make sure folder also contains an init.py, this allows it to be included as a package.