Reputation: 24500
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
Upvotes: 0
Views: 29
Reputation: 11228
a.do
was hint, implying that, you need to import a and then in that import there is a method/function do, which will execute.
# Write your code here
from branch1 import solution as a
from branch2 import solution as b
# Keep the code below
a.do()
b.do()
Upvotes: 0
Reputation: 160
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
Upvotes: 1