Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to import and call same named functions from 2 folders in 1 project space in python?

how to rename the imported file with the same name?

There are folders named branch1 and branch2 under PROJECT in our current work project, and there is a file with the same name solution.py in these two folders.

# Write your code here
from branch1 import do as a
from branch2 import do as b
# Keep the code below
a.do()
b.do() #but it's not working

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So, what I have seen in your given link is-

You have two folders called branch1 and branch2. Each of the folder has a file named solution.py and there is a do function inside that.

The problem statement tells you to import the solution files and rename them so that you can use them without collisions. If you see the code snippet, the key is in a.do() and b.do(). You are not importing do functions, but the solution files.

The problem you are having is in the line

from branch1 import do as a

You are trying to import the function do as a directly. There is no do.do(). So they don’t work. Based on your problem statement, the import statement should be-

from branch1 import solution as a
from branch2 import solution as b

a.do()
b.do()

You will get an output like below if you run this-

We are running in branch/branch1.solution.py
We are running in branch/branch2.solution.py
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading