sharath
sharath

Reputation: 55

calling a function with same name and same parameters

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

Answers (3)

dm03514
dm03514

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

Jerome Vacher
Jerome Vacher

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

Timur Osadchiy
Timur Osadchiy

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

Related Questions