Choosing a style when referring to modules in Python
by Turbocapitalist from LinuxQuestions.org on (#52N4C)
When writing in Python, which style is prefereable when using modules?
In one style you could use them like this:
Code:. . .
from multiprocessing import Process, Value, Array
. . .
w=Value('i')
. . .With another style you could use them like this:
Code:. . .
import multiprocessing
. . .
w=multiprocessing.Value('i')
. . .Is either style preferable? I'm guessing the second example would be preferable because it is less ambiguous which module is in use. What kind of difference is there in regards to cluttering either source code or memory? Maybe it makes more of a difference in longer scripts as opposed to shorter ones.


In one style you could use them like this:
Code:. . .
from multiprocessing import Process, Value, Array
. . .
w=Value('i')
. . .With another style you could use them like this:
Code:. . .
import multiprocessing
. . .
w=multiprocessing.Value('i')
. . .Is either style preferable? I'm guessing the second example would be preferable because it is less ambiguous which module is in use. What kind of difference is there in regards to cluttering either source code or memory? Maybe it makes more of a difference in longer scripts as opposed to shorter ones.