import statement convention
Steve Holden
steve at holdenweb.com
Tue Apr 8 22:35:33 EDT 2008
Ben Finney wrote:
> MartinRinehart at gmail.com writes:
>
>> By convention, I've read, your module begins with its import
>> statements. Is this always sensible?
>
> There are exceptions, but the benefits are great: It's very easy to
> see what this module requires, without needing to execute it.
>
>> I put imports that are needed for testing in the test code at the
>> end of the module. If only a bit of the module has a visual
>> interface, why pollute the global namespace with 'from Tkinter
>> import *'? Wouldn't that be better done in a separate class or
>> function?
>
> If your test code requires the Tkinter module but the rest of the code
> doesn't, why pollute the functional module with such test code? Move
> it to a separate unit test module.
>
If your test code is the only part of the module that needs Tkinter I'd
be perfectly happy seeing the import guarded by the if __name__ ==
"__main__" condition.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list