Importing Third-Party Classes in Python Scripts
Short answer
A Before calling a class from a third-party library, import its module with import or from... import statements so the name is defined at runtime.
Question
Key Takeaways
The question tests Python module namespace rules; the trap is assuming external classes are globally available without an explicit import.
Python requires an import or from... import statement to bind a third-party library class into your script before it can be called, making this statement TRUE (A).
Common mistake: Choosing B (FALSE) by assuming third-party classes are automatically accessible or already loaded by the runtime; they are not, and skipping the import causes a NameError.
Expert Analysis
The core rule
In Python, a third-party library's classes are not placed in your program's namespace automatically. Before you can instantiate or call a class that lives in an external package, you must first bind it into the current module with import package or from package import Class. Only after that statement executes can you reference Class or package.Class — otherwise Python raises NameError: name 'Class' is not defined. A community comment makes exactly this point: external classes are not available automatically, so you must import the module or the class first. That confirms option A (TRUE) as the correct choice.
What else this knowledge covers
The adjacent decision is which import form to use. import numpy keeps names namespaced (numpy.array), while from numpy import array imports the symbol directly — both satisfy the requirement, and mixing them carelessly is what usually causes confusion. The scenario that would flip the answer is a name already present in scope: a class defined in the same file, one injected by a framework (for example Flask/Django decorators or a notebook's preloaded globals), or a builtin such as dict — those need no import, so the statement is not universally true for every callable, but as written about third-party libraries it holds.
Operational consequence of getting it wrong
Missing or misplaced imports produce runtime failures at the moment of first use, not at parse time. Forgetting an install (pip install) alongside the import also yields ModuleNotFoundError. In automation scripts (objective 7.2), this is a top source of broken jobs, so verify both the dependency installation and the import line at the top of the script.
Exam Strategy
For Python true/false items, read the wording strictly: absolute words like "must" are usually correct when describing core language mechanics such as namespace binding. Ask yourself whether the name exists in the module scope without extra code; for third-party symbols it never does, so pick TRUE. If a scenario adds that the class is defined in the same file or preloaded by a framework, the import requirement disappears and the answer flips.
Frequently Asked Questions
Why do I get NameError when calling a class from an installed package?
What is the difference between import module and from module import Class?
import module requires qualified access like module.Class, while from module import Class lets you call Class directly, at the cost of polluting the local namespace.Does every function or class call in Python need an import statement?
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 1 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 1
-
1b20e93 👍 1 Answered AEn Python, las clases de una biblioteca externa no están disponibles automáticamente. Primero debes importar el módulo o la clase.
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.