from package import * without overwriting similarly named functions?

Mike Driscoll kyosohma at gmail.com
Fri Oct 24 14:20:12 EDT 2008


On Oct 24, 1:06 pm, Reckoner <recko... at gmail.com> wrote:
> I have multiple packages that have many of the same function names. Is
> it possible to do
>
> from package1 import *
> from package2 import *
>
> without overwriting similarly named objects from package1 with
> material in package2? How about a way to do this that at least gives a
> warning?
>
> Thanks.

You can't do something like this:

from package1 import bork
from package2 import bork

and expect python to know that you want the bork from the first
package at one point and the other at another point. The latter will
basically overwrite the former. You should just import them like this:

import package1
import package2

package1.bork()
package2.bork()

Then Python will know what to do. If the name of the package is long,
you can do this too:

import reallylongnamedpackage as p

then it would be p.bork()

Then again, python is open source. Thus, you can modify the source to
do whatever you want if you have the patience and the knowledge to do
so.

Mike



More information about the Python-list mailing list