In python console I can run:
from random import randint
But I get an error when I run:
import random.randint
The error says:
ModuleNotFoundError: No module named 'random.randint'; 'random' is not a package
I thought the two import statements were synonymous. Perhaps I'm missing something?
import random.randint
is parsed as the import of a submodule named randint
from a package named random
.
The error message is trying to tell you that random
is not a package with a submodule. In fact it's just a single module, random.py
, and randint
is a method defined in that module.
You may use this:
from random import randint
randint(...)
Or this:
import random
random.randint(...)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.