- A
mymodule.py
Why wrong: __name__ does not include .py extension.
- B
__main__
Why wrong: This is only for the top-level script.
- C
mymodule
The module's __name__ is the dotted name used in import.
- D
/custom/path/mymodule.py
Why wrong: That's __file__ attribute, not __name__.
Quick Answer
The answer is 'mymodule' because when Python imports a module, it assigns the `__name__` attribute the module's name as a string, not the filename with the .py extension. This attribute reflects the module's import name, which in this case is simply 'mymodule', regardless of the custom path where the file resides. On the Certified Associate Python Programmer PCAP exam, this concept tests your understanding of how Python manages module attributes and the import system, often appearing in questions that try to trick you into thinking `__name__` equals the full file path or includes the extension. A common trap is confusing `__name__` with `__file__`, which does store the path. Remember this key distinction: `__name__` is the logical name used in the import statement, while `__file__` is the physical location. A helpful memory tip is to think of `__name__` as the module's "identity badge" — it always shows how you referred to it in the import, not where it lives on disk.
PCAP Modules and Packages Practice Question
This PCAP practice question tests your understanding of modules and packages. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
A developer runs the following code in a script that is not part of a package:
import sys
sys.path.insert(0, '/custom/path')
import mymodule print(mymodule.__name__)
What is the output if 'mymodule' is found at '/custom/path/mymodule.py'?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
mymodule
Option C is correct because when a module is imported, Python assigns the `__name__` attribute to the module's name as a string (e.g., 'mymodule'), not the filename with extension. Since the script is not part of a package and the module is found at a custom path, `mymodule.__name__` is simply 'mymodule'.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
mymodule.py
Why it's wrong here
__name__ does not include .py extension.
- ✗
__main__
Why it's wrong here
This is only for the top-level script.
- ✓
mymodule
Why this is correct
The module's __name__ is the dotted name used in import.
Related concept
Read the scenario before looking for a memorised answer.
- ✗
/custom/path/mymodule.py
Why it's wrong here
That's __file__ attribute, not __name__.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Python Institute often tests the distinction between `__name__` and the file path or extension, hoping candidates confuse the module's name with its filename or full path.
Detailed technical explanation
How to think about this question
Under the hood, when Python imports a module, it creates a module object and sets its `__name__` attribute to the string used in the import statement (e.g., 'mymodule'). The `sys.path` list determines where Python searches for modules, but the `__name__` attribute is independent of the file's location. In real-world scenarios, this distinction is critical for conditional execution (e.g., `if __name__ == '__main__'`) and for debugging imports in complex projects.
KKey Concepts to Remember
- Read the scenario before looking for a memorised answer.
- Find the constraint that changes the correct option.
- Eliminate answers that are true in general but not in this case.
TExam Day Tips
- Watch for words such as best, first, most likely and least administrative effort.
- Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A cloud solutions architect for a retail company is evaluating services for a new workload. The correct answer here reflects best practice for the specific scenario described — not a general cloud recommendation. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Cloud exam questions reward reading the constraint carefully: the same technology can be right or wrong depending on the use case.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
- →
Modules and Packages — study guide chapter
Learn the concepts, then practise the questions
- →
Modules and Packages practice questions
Targeted practice on this topic area only
- →
All PCAP questions
511 questions across all exam domains
- →
Certified Associate Python Programmer PCAP study guide
Full concept coverage aligned to exam objectives
- →
PCAP practice test guide
How to use practice tests most effectively before exam day
Related practice questions
Related PCAP practice-question pages
Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.
Modules and Packages practice questions
Practise PCAP questions linked to Modules and Packages.
Strings practice questions
Practise PCAP questions linked to Strings.
Object-Oriented Programming practice questions
Practise PCAP questions linked to Object-Oriented Programming.
Exceptions and File I/O practice questions
Practise PCAP questions linked to Exceptions and File I/O.
PCAP fundamentals practice questions
Practise PCAP questions linked to PCAP fundamentals.
PCAP scenario practice questions
Practise PCAP questions linked to PCAP scenario.
PCAP troubleshooting practice questions
Practise PCAP questions linked to PCAP troubleshooting.
Practice this exam
Start a free PCAP practice session
Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.
FAQ
Questions learners often ask
What does this PCAP question test?
Modules and Packages — This question tests Modules and Packages — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: mymodule — Option C is correct because when a module is imported, Python assigns the `__name__` attribute to the module's name as a string (e.g., 'mymodule'), not the filename with extension. Since the script is not part of a package and the module is found at a custom path, `mymodule.__name__` is simply 'mymodule'.
What should I do if I get this PCAP question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.