Reputation: 11
I'm making a random name generator, but my guide book uses import sys, random
instead of just import random
. I tried looking at Google to see what the differences between the two imports are, but I couldn't find anything. Is there any difference between the two statements?
Upvotes: 0
Views: 903
Reputation: 712
Separating imports with commas as below
import random, sys
is the same as
import random
import sys
However, according to PEP8, it is recommended to separate your imports to ensure clarity. Moreover, in case any of the imports fail the traceback is more informative and you know exactly which library failed.
Upvotes: 4
Reputation: 105
import sys, random
is importing 2 different modules: sys
and random
. However, import random
will only import the random
module. If the script in your book is importing the sys
as well as the random
module, it probably means it will also use system-related features from the sys
module.
Upvotes: 0
Reputation: 1321
It means that in addition to importing the random
library, they are importing the sys
library as well, which means they are probably accessing some functions in that library. Check the entire code to see where they access it.
Upvotes: 3