+ 2

Really worth to avoid import *(star) from Python??

I heard I should avoid "import *" as this could cause many problems. So ended up as below: import tkinter from tkinter import messagebox, Frame, filedialog, Pack, Tk, Label, Button, StringVar, Entry from tkinter import BOTH, LEFT, RIGHT, TOP, FLAT, CENTER hmm.. is this the best practice? It doesn't look right. It's too many.

1st Nov 2017, 9:50 AM
John S.R. LEE
John S.R. LEE - avatar
2 Respostas
+ 8
from lib import * has a benefit - you can cast lib's method's without its name, so instead of lib.method() you just write method() But that's about it, no additional benefits from that. The danger is that if you don't know the lib too well, you might have just overwritten another methods you use, that come as built-ins. For example, if lib contains a print() method, importing with an asterisk makes the default print() inaccessible :( So heed the warning.
1st Nov 2017, 10:29 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
You should really just put it. If you just put, from tkinter import, nothing good would happen.
3rd Nov 2017, 1:14 AM
Hyrum Harris
Hyrum Harris - avatar