Import from file with same name but other directory

Viewed 14

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?

2 Answers

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.

Related