10

I know how to use both, but I'm curious why the decision was made to make one a statement and the other a function.

user2229219
  • 320
  • 3
  • 14

1 Answers1

7

First of all you can import using a function, from importlib's documentation:

The __import__() function
The import statement is syntactic sugar for this function.

for instance both of these statements are equivalent:

from random import randint as random_int

random_int = __import__("random").randint

However the import statement greatly benefits from alternate syntax where as reload does not really have any alternate meaning.

I can also imagine a lot of beginner programmers making this mistake if reload was it's own statement:

from random import *
reload random #does not affect the current namespace!

Since the reload function requires a module (which is not preduced with from _ import *) coders may wonder why the names imported are not reloaded. related to this answer

Community
  • 1
  • 1
Tadhg McDonald-Jensen
  • 19,220
  • 4
  • 32
  • 57