Reputation: 55
I have two functions a() in a.py and a() in b.py.How do i call the function of a.py a() in b.py. Since both the functions will have same name in b.py i am not able to figure out how to do it.
Upvotes: 0
Views: 52
Reputation: 55972
You can import your module and access its methods so there are no naming collisions:
# b.py
import a
a.a()
Upvotes: 4
Reputation: 324
Tips: In a general point of view avoid using:
from module import * # IS BAD !
it is a huge source of missunderstanding. If you do it to save the size and readability of you code prefer :
import module.which.may.be.super.long as M
M.a()
you save the trace-ability of your code, keeping Python as an explicit language.
Upvotes: 0
Reputation: 6229
First approach is:
import a
import b
a.a()
b.a()
Another is:
from a import a as a_a
from b import a as b_a
a_a()
b_a()
Upvotes: 1