Do the below 2 import statements have some difference? Or just the same thing?
from package import *
import package
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
from package import *imports everything from package into the local namespace; this is not recommended because it may introduce unwanted things (like a function that overwrites a local one). This is a quick and handy import tool, but if things get serious, you should use thefrom package import X,Y,Z, orimport packagesyntax.import packageimports everything from package into the localpackageobject. So if package implements thesomething()function, you will use it bypackage.something().Also, another thing that should be talked about is the nested namespace case: suppose you have the function
package.blabla.woohoo.func(), you canimport package.blabla.woohooand usepackage.blabla.woohoo.func(), but that is too complicated. Instead, the easy way to do it isfrom package.blabla import woohooand then usewoohoo.func()orfrom package.blabla.woohoo import func, and then usefunc(). I hope this makes sense. If it doesn’t, here’s a code piece to illustrate:Hope this helps 🙂