Bird
0
0

Consider this folder structure:

medium📝 Predict Output Q4 of 15
Python - Modules and Code Organization
Consider this folder structure:
project/
__init__.py
utils.py

with __init__.py containing:
from .utils import add

and utils.py containing:
def add(x, y):
return x + y

What will be the output of:
import project
print(project.add(3, 4))
AError: 'add' is not an attribute of 'project'
B7
CNone
DError: circular import
Step-by-Step Solution
Solution:
  1. Step 1: Analyze import statement

    The __init__.py imports add from utils but does not expose it as a package attribute.
  2. Step 2: Check attribute access

    Since add is imported inside __init__.py but not assigned to __all__ or explicitly exposed, project.add is not accessible.
  3. Step 3: Result

    Attempting to access project.add raises an AttributeError.
  4. Final Answer:

    Error: 'add' is not an attribute of 'project' -> Option A
  5. Quick Check:

    Imported functions must be exposed to package namespace [OK]
Quick Trick: Imported functions need explicit exposure to package [OK]
Common Mistakes:
  • Assuming imported functions are automatically package attributes
  • Confusing import inside __init__.py with exposure
  • Expecting functions to be accessible without explicit export

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes