Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a point to import the same module in two different ways in a program?

Is there a point to import as both wildcard and non-wildcard manner like:

import spam as sp
from spam import *

in the very same file?

like image 634
Nae Avatar asked Dec 12 '25 13:12

Nae


1 Answers

When you import spam as sp, you make sure that there are no conflicts with other import commands:

import spam as sp
import myfunctions as my

sp.foo()
my.foo()

This is working as expected, but this isn't:

from spam import *
from myfunctions import *


foo()
foo() #Which foo() is meant? UNCLEAR!!!

When you avoid this problem by using import spam as sp, why would you want to use from spam import * anyways? I don't think there is any point in this.

like image 54
monamona Avatar answered Dec 14 '25 04:12

monamona



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!