Module import best practice

Rich Shepard rshepard at appl-ecosys.com
Thu Mar 26 14:07:37 EDT 2020


On Thu, 26 Mar 2020, Schachner, Joseph wrote:

> I can only tell you my preference. I prefer that Python modules be as
> self-contained as possible, because "global" is within a module; to share
> between modules you have to import something, as you know.

Joseph,

This makes good sense. I don't know that I'll end up with a chain of
namespaces, but I should avoid that possiility.

If I understand your reasoning, within commonDlg.py I should import required
modules for each class and not all of them at the beginning of the file. And
each module that uses classes from commonDlgs should include 'from commonDlg
import ...' only the classes it needs, even when there are several (but not
all commonDlg classes).

Is this correct?

Many thanks,

Rich



More information about the Python-list mailing list