When to import

Anders M Eriksson anders.eriksson at morateknikutveckling.se
Wed Jun 14 04:01:18 EDT 2000


Hello!

Being a hard-to-die C programmer I would like to know if the Python
community has any recommendation about this.

When does the import take place?
Will there be any difference in the two cases below?
If I have a module that I very seldom use should I only import it when
needed (using an if statement) or is it better to allways import it?

// Anders



# case 1
import module1
import module2


rc = module1.function1()
if rc == 1:
	rc = module2.function1()

#case 2

import module1

rc = module1.function1()
if rc == 1:
	import module2
	rc = module2.function1()





More information about the Python-list mailing list