Confusion regarding importing


#1

how are generic imports different from universal imports? aren’t they basically doing the same thing?


#2

on the surface it might appear so, but there is a massive difference:

# generic import
import math

print math.sqrt(25)

# universal import
fom math import *

print sqrt(25)

The universal import means a lot of names will be taken, which might result in naming conflict. If you do generic import, to access function of the module you have to module.function_name. Makes it a lot easier to prevent naming conflict, which is a good thing especially if the project grows.

Always use generic import, unless you have a very very very good reason not to.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.