What Does Python's __init__.py Do? (Quiz)

Become a Member to take the quiz.

Avatar image for gregmoody248

gregmoody248 on March 11, 2026

Using the example code provided, Could you put the “from random import randint” statement in the init module so that you would not have to include that statement in both the income.py and outgo.py?

Avatar image for Steven Loyens

Steven Loyens RP Team on March 14, 2026

Hey, thank you for your question. I see why you would think that but that’s not quite how it works.

Importing random in __init__.py makes random an attribute of the package itself. This allows an external user to type import my_package and then access my_package.random, but it doesn’t make the module available to your other internal files. You still need to import it into each individual module where you intend to use it.

Become a Member to join the conversation.