← Back to videos

Python mock interview: imports that cause errors

Interview timeline Click any block to jump

Interview breakdown

Interviewer verdict
Passed interview Level: Entry-level Junior / strong Intern (6–7/10)

The candidate passed at an entry-level Junior / strong Intern bar (rated 6–7/10 by the interviewer): communicated confidently, reasoned logically, and adapted hypotheses gracefully when shown counterexamples. The main growth area is deepening under-the-hood runtime knowledge of module execution on import, sys.modules caching, and function-local namespace rules.

Candidate: Roman
Target role: Junior Python Developer

22 y/o · studying Python for ~5 months via Yandex Practicum (currently on the Django module), no prior commercial experience

Answers accuracy 14 total
57% score
Theory
4/11 correct · 59%
Live coding
1/3 correct · 50%
Practical task
Partially solved

Why from math import * raises SyntaxError inside a function and how local imports work

The candidate initially predicted def f(x): from math import *; return x + floor(2.7) would run cleanly. After seeing SyntaxError, he immediately hypothesized and verified that both 'from math import floor' and 'import math' work inside a function and accurately traced module-vs-function execution order, though he misattributed the wildcard import ban to a memory/reference count limit rather than compile-time local scope analysis.

Topics covered Click a topic to filter questions

Candidate strengths

  • + Confident, articulate communication and composure on an unexpected topic
  • + Intellectual flexibility: willingness to revise assumptions constructively when presented with new runtime evidence
  • + Solid command of PEP 8 import ordering, grouping, and cleanup conventions
  • + Sound step-by-step hypothesis testing during the live code-reading exercise

Areas to improve

  • → Learn what actually happens on first vs repeated imports: top-level module execution and sys.modules caching
  • → Study absolute vs relative imports (from . import ...) and module search path resolution via sys.path
  • → Understand why 'from module import *' is a SyntaxError inside functions (compile-time fast-locals slot determination)
  • → Build the habit of testing edge cases of everyday syntax experimentally

Questions in this interview

14 / 14
01 ▶ 04:00
How does import syntax work in Python, and what kind of language entity is 'import'?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Identified import and from as Python keywords used to bring whole modules or specific functions, classes, and constants into scope.

Key takeaway

import and from ... import ... are language statements backed at runtime by __import__() and the importlib machinery.

Open moment on YouTube ↗
#01
02 ▶ 05:50
How do a module, a package, and a library differ, and can you import a package directly?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Correctly ordered module (.py file) -> package -> library, but mistakenly guessed that a package itself cannot be imported directly.

Key takeaway

A package is a directory of modules that is itself a module object at runtime; 'import package' is valid and executes its __init__.py.

Open moment on YouTube ↗
#02
03 ▶ 07:57
What is Python's standard library, what does a package manager do, and what security risks come with third-party packages?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Defined the standard library accurately and cited real typosquatting supply-chain attacks on PyPI, though he got slightly confused classifying pip vs stdlib modules.

Key takeaway

The stdlib ships with Python, whereas third-party distributions come from PyPI via pip/uv/poetry — requiring care against typosquatting and malicious dependencies.

Open moment on YouTube ↗
#03
04 ▶ 11:16
What actually happens when you import a single function (from my_module import func) from a file that also contains other functions and top-level code?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Assumed Python merely creates a reference to the requested function without executing the rest of the target module.

Key takeaway

Even 'from my_module import func' executes the entire my_module.py top-to-bottom on first import, caches the module in sys.modules, and then binds the requested attribute name.

Open moment on YouTube ↗
#04
05 ▶ 13:11
How does Python know which directories to search for an imported module, and can custom search paths be added?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Reasoned that Python checks default stdlib/site-packages folders and likely supports custom directories, without naming sys.path or PYTHONPATH.

Key takeaway

Python checks sys.modules first, then built-ins, and then searches directories listed in sys.path (script directory, PYTHONPATH, stdlib, and venv site-packages).

Open moment on YouTube ↗
#05
06 ▶ 17:37
What happens if the same module or function is imported a second time later in the program?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Initially mentioned duplicate references, then corrected himself that Python avoids reloading an already imported module and reuses the existing object without error.

Key takeaway

Imported modules are cached as singletons in sys.modules, so subsequent imports simply look up the existing module object without re-executing its file.

Open moment on YouTube ↗
#06
07 ▶ 20:45
If an imported function contains an error, does the program fail at the import statement or when the function is called?
Theory Exceptions & debugging
?
Candidate's answer

Said errors surface at runtime when the script runs, without separating SyntaxErrors/top-level errors (raised at import time) from runtime errors inside the function body (raised at call time).

Key takeaway

A SyntaxError anywhere in the module or an exception at top level fails immediately during import, whereas runtime bugs inside a def body fail only when that function is called.

Open moment on YouTube ↗
#07
08 ▶ 22:17
Where and in what order should imports be placed according to PEP 8, and are imports inside functions allowed?
Theory Algorithms, code reading & engineering practices
?
Candidate's answer

Accurately listed PEP 8 rules — top of file in three blank-line-separated groups (stdlib, third-party, local), removing unused imports — and noted local imports inside functions/methods work too.

Key takeaway

PEP 8 places imports at module top (stdlib, third-party, local); function-level imports are reserved for breaking circular imports or deferring heavy optional dependencies.

Open moment on YouTube ↗
#08
09 ▶ 29:28
How does 'import math' differ from 'from math import *', and why is the latter discouraged?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Quickly distinguished them: 'import math' binds a single module reference accessed via dot notation, whereas 'from math import *' dumps all module names into the current scope.

Key takeaway

Wildcard imports pollute the namespace, risk silently shadowing existing names, and obscure symbol provenance for readers and linters.

Open moment on YouTube ↗
#09
10 ▶ 31:25
What are absolute and relative imports in Python?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Admitted he did not know the terms and guessed 'absolute import' meant importing an entire library.

Key takeaway

Absolute imports specify the full path from sys.path root (from app.services import auth), while relative imports use leading dots relative to the current package (from . import utils).

Open moment on YouTube ↗
#10
11 ▶ 32:15
Does Python's import simply paste file contents together like template inclusion in Django?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Correctly contrasted template rendering with Python imports, explaining that import binds references to module objects rather than copy-pasting source text.

Key takeaway

Unlike C's textual #include, every Python module keeps its own isolated global namespace (__dict__), and import only binds object references.

Open moment on YouTube ↗
#11
12 ▶ 34:03
Will def f(x): from math import *; return x + floor(2.7) followed by print(f(10)) run without error?
Live coding Modules, packages, imports & stdlib
?
Candidate's answer

Predicted the code was valid and would return 10 plus floor(2.7).

Key takeaway

In Python 3, 'from module import *' is a compile-time SyntaxError anywhere except module top level ('import * only allowed at module level').

Open moment on YouTube ↗
#12
13 ▶ 39:23
Why do 'from math import floor' and 'import math' work inside a function while 'from math import *' is a SyntaxError?
Live coding Python internals, bytecode & runtime
?
Candidate's answer

Immediately proposed working fixes using 'from math import floor' and 'import math', but mistakenly guessed wildcard import fails due to a memory/reference limit inside functions.

Key takeaway

CPython statically resolves function locals into fixed-offset fast-local slots (LOAD_FAST) at compile time; wildcard imports would make local names unknowable before runtime.

Open moment on YouTube ↗
#13
14 ▶ 47:22
What happens if 'import math' appears both at the top of the file and inside f(), and in what order does Python initialize the script?
Live coding Functions, scopes & closures
?
Candidate's answer

Correctly predicted no conflict: Python executes the top-level import first, defines function f next, and reuses the already loaded module when f() runs.

Key takeaway

Writing 'import math' inside a function binds a local variable 'math' in the function's frame pointing to the exact same cached module object in sys.modules.

Open moment on YouTube ↗
#14
Original video description & timecodes

A mock interview for a Junior Python Developer role, in which the conversation unexpectedly veered entirely towards the topic of imports. We break down what an import is, the differences between a module, a package and a library, what actually happens during an import, when the module’s code is executed, and why using `import *` inside a function can break the programme.

It turned out to be not just an interview, but an in-depth analysis of one of the most fundamental and underrated topics in Python. At the end — detailed feedback for the candidate: what went well, where the mistakes were, and how to grow more quickly into a confident junior developer.

Timecodes

00:00 Start
00:26 Introduction
01:36 Roman talks about himself
02:08 Interview format
04:00 Episode topic — imports in Python
05:50 Module, package, library
07:57 Package manager and libraries
11:16 What happens during an import
17:37 Re-importing and potential errors
22:17 Where to import correctly
25:27 Importing a module or individual functions
31:25 Absolute and relative imports
33:41 Code review
39:23 Why code fails with `import *`
47:22 Scopes and import conflicts
50:26 Final feedback
51:32 Roman’s self-assessment
52:02 Review of strengths and weaknesses