Any difference between the two imported ones?

Are there any differences in the two import statements? Or just the same thing?

from package import *

import package
+5
source share
2 answers

from package import *Imports everything from the package to the local namespace this is not recommended because it can lead to unwanted things (for example, to a function that overwrites the local one). This is a quick and convenient import tool, but if the situation becomes serious, you should use the from package import X,Y,Zor syntax import package.

import packageimports everything from the package into a local object package. Therefore, if a package implements a function something(), you will use it package.something().

, : , package.blabla.woohoo.func(), import package.blabla.woohoo package.blabla.woohoo.func(), . from package.blabla import woohoo, woohoo.func() from package.blabla.woohoo import func, func(). . , , :

import package.blabla.woohoo
package.blabla.woohoo.func()

from package.blabla import woohoo
woohoo.func()

from package.blabla.woohoo import func
func()

, :)

+12

.

from package import *
class_in_package()

import package
package.class_in_package()
+3

All Articles