27 Jul, 2009, Lobotomy wrote in the 1st comment:
Votes: 0
I'm having some slight difficulties with Python's import statement(s), and I'm wondering about the following: If you use "from module import *" on a particular module, and that module contains another module, is it supposed to not include that other module? It currently seems to be working that way, but I wanted to be sure that's the actual/desired functionality.

For instance, I'm having a script that does "from tkinter include *" to get all of tkinter's things so that I don't have to preface everything I want from that with tkinter.(etc). The tkinter module contains (what appears to be?) another module, filedialog, used to run various sorts of common file dialog operations like open file, open directory, save as, and so on. As it stands, when I have it run "from tkinter include *" it's not actually importing filedialog as well; trying to reference it makes Python throw an exception. So, I end up having to go:

from tkinter import *
import tkinter.filedialog

So, again, I must ask, is that how it's supposed to work?

Also, in the case of the above example what would be the convention for how the include statements should be ordered? The way it currently is as stated, or the other way around?
27 Jul, 2009, Idealiad wrote in the 2nd comment:
Votes: 0
You have it right, you only get the namespace that you explicitly import. Also while it's tempting to use import *, in general I would try to avoid it, as you lose the benefits of the module's namespace. If you want you can do something like import tkinter as tk if you want a shorter piece of code.

As for order of imports I think people usually go from the general to the specific like you did, perhaps with library modules in one block and then 3rd party/custom modules in a second group. I don't think it's too important.
27 Jul, 2009, Lobotomy wrote in the 3rd comment:
Votes: 0
Ah, I see. Thank you. :smile:
0.0/3