Toplevel "test()" functions in standard library
Moshe Zadka
moshez at math.huji.ac.il
Wed Jul 19 05:50:57 EDT 2000
On 19 Jul 2000, Rob Hooft wrote:
> In the standard library there is about 20 modules with the construction:
>
> ------------------------------------------
> [module definitions]
>
> def test():
> [testing code or general main program]
>
> if __name__=="__main__":
> test()
> ------------------------------------------
>
> Wouldn't it be better to move the test() definition inside the if
> statement in these cases, to prevent name space pollution? Note that
> the routines are not called "_test()", so they will be imported by a
> "from ... import *" (There are other modules with a _test() definition
> as well).
Anyone using from ... import * is inviting trouble.
The routines are called _test() in all "import *"-safe modules.
> Even worse: the test() routine might have severe side effects:
> e.g. base64.test() will block waiting for data from stdin...
Well, it's a test routine
> Going one step further: Should all of these "test()" and "_test()"
> routines be in the code library at all, even now that we have a
> complete test engine?
Yes! This is a preliminary test, which should be available to every user
of the library. If you're optimizing the few KB it takes, then you're not
using Python correctly.
--
Moshe Zadka <moshez at math.huji.ac.il>
There is no GOD but Python, and HTTP is its prophet.
http://advogato.org/person/moshez
More information about the Python-list
mailing list