xiº
xiº

Reputation: 4687

Two packages which contain modules with same name

Let's say we have two python packages.

First one called lib1 and contains sample module.

In setup.py our name is name='lib1'.

So after installing, we could just use it as import sample.

But what if lib2 contains module sample?

Seems there will be a conflict.

How to deal with it? Is there any agreements?

lib1
    sample
    tests
    setup.py


lib2
    sample
    tests
    setup.py

Upvotes: 1

Views: 338

Answers (2)

Marcel Wilson
Marcel Wilson

Reputation: 4572

Use alias or be very deliberate with your references to those libraries

import package1
import package2

# There should be no mistaking which function is being called this way
package1.module.function()
package2.module.function()

Upvotes: 0

Pippo
Pippo

Reputation: 925

Just define an alias for the module in each package when importing...

something like:

import package1.module as uniquemod1
import package2.module as uniquemod2

Upvotes: 1

Related Questions