Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does from `from itertools import chain` works but not `import itertools.chain as chain`?

Why does the following work:

from itertools import chain

but the following does not?

import itertools.chain as chain
like image 813
alvas Avatar asked Oct 31 '25 16:10

alvas


1 Answers

The import foo.bar syntax can only be used to import a module from a package, not an object in a module. from foo import bar can be used to import a module from a package or an object from a module.

like image 62
BrenBarn Avatar answered Nov 04 '25 00:11

BrenBarn