Python: Unterschied zwischen Import Modul und From Modul Import *?
Frage steht oben.
Es scheint doch das Gleiche zu sein oder nicht?
4 Antworten
![](https://images.gutefrage.net/media/user/Brockdish/1658613668615_nmmslarge__0_0_1024_1024_3ee6d102f9fff3b8eb89a9336cca61ab.png?v=1658613669000)
Also wenn du schreibst (empfohlen von mir) :
from tkinter import*
Dann kannst du schreiben:
window = Tk()
Aber wenn du schreibst:
import tkinter
Dann musst du immer schreiben:
window = tkinter.Tk()
![](https://images.gutefrage.net/media/user/Dory1/1463259757316_nmmslarge__113_0_387_387_9cc3321f365109157e4332f57e79e665.png?v=1463259759000)
https://stackoverflow.com/questions/710551/use-import-module-or-from-module-import
import modulePros: Less maintenance of your import statements. Don't need to add any additional imports to start using another item from the module
Cons: Typing module.foo in your code can be tedious and redundant (tedium can be minimized by using import module as mo then typing mo.foo)
from module import fooPros: Less typing to use foo. More control over which items of a module can be accessed
Cons: To use a new item from the module you have to update your import statement. You lose context about foo. For example, it's less clear what ceil() does compared to Math.ceil()
![](https://images.gutefrage.net/media/default/user/14_nmmslarge.png?v=1551279448000)
Überhaupt nicht.
import tkinter
Fenster = tkinter.Tk()
oder
from tkinter import *
Fenster = Tk()
oder(von mir empfohlen
import tkinter as tk
Fenster = tk.Tk()
![](https://images.gutefrage.net/media/user/ohwehohach/1484229011333_nmmslarge__192_3_203_203_916b80d33227bc2c78789585f46b3253.jpg?v=1484229011000)
Es gibt schon Unterschiede, wie hier in der akzeptierten Antwort beschrieben: