How to force built-in commands over imported.

Delaney, Timothy tdelaney at avaya.com
Wed Sep 4 19:16:12 EDT 2002


> From: Simon Brunning [mailto:SBrunning at trisystems.co.uk]
>  
> You are, I assume, importing 'os' as follows:
> 
> from os import *
> 
> *Don't* *do* *this*. Use:
> 
> import os
> 
> instead. There *are* reasons for using the former method, but 
> they are few
> and far between. The latter form should always be the one you 
> use unless you
> have a good reason.

Indeed. The only time I have *ever* found to do this (I don't use TKinter ;)
is in the following scenario:

	# UnitTests.py

	import unittest

	from tests1 import *
	from tests2 import *

	if __name__ == '__main__':
		 unittest.main()

	# tests1.py

	import unittest

	class Test1 (unittest.TestCase):

		 def test1 (self):
		pass

	if __name__ == '__main__':
		 unittest.main()

	# tests2.py

	import unittest

	class Test2 (unittest.TestCase):

		 def test2 (self):
		pass

	if __name__ == '__main__':
		 unittest.main()

which allows me to perform each set of tests independently, and run them all
through a single command. Even so, it should probably specify the actual
names of the test cases in case there is a conflict somewhere, but that
would fail to pick up any new test cases.

Tim Delaney




More information about the Python-list mailing list