-2

I want to use count function from itertools module. When I try to import full module

import itertools 

The count function isn't accessible. I can use it only when I import it like this

from itertools import count

how I can import full module functions without importing them one by one

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Naglyj.Spamer
  • 71
  • 2
  • 9
  • Are you trying to call `count`, or `itertools.count` in the first case? When using `import X` syntax, you always have to qualify names from the module with `X.`. You could avoid namespace qualification with `from itertools import *`, but [that's generally frowned on](https://www.python.org/dev/peps/pep-0008/#imports) (namespaces are a good thing for avoiding accidental name collisions, and using `from x import *` prevents static analyzers from doing their job as well). – ShadowRanger Jul 05 '19 at 12:48
  • I call count without mentioning itertools. Now I understood what I was doing wrong . Thank you – Naglyj.Spamer Jul 05 '19 at 12:50

1 Answers1

0

In case you only need the count function it is much more economical to use

from itertools import count

If you need the whole module just import it like this:

from itertools import *  # to be avoided due to potential name collusions

print(count(10))

or import everything using the module's full name:

import itertools

print(itertools.count(10))

or use a shortcut to itertools:

import itertools as it

print(it.count(10))
M. Weeker
  • 140
  • 2
  • 10