POC Implementation & Configuration 2 — Questions and Answers
Question 1: Which pip command installs a package in 'editable' (development) mode from a local directory?
- pip install --dev .
- pip install -e . (Correct answer)
- pip install --editable=local .
- pip install --source .
Correct answer: pip install -e .
The `-e` flag (short for `--editable`) installs a package so changes in the source directory are immediately reflected without reinstalling.
Question 2: What is the purpose of a `pyproject.toml` file in a Python project?
- It stores runtime environment variables
- It defines build system requirements and project metadata per PEP 517/518 (Correct answer)
- It replaces the Python interpreter configuration
- It lists installed packages like requirements.txt
Correct answer: It defines build system requirements and project metadata per PEP 517/518
`pyproject.toml` is the modern standard (PEP 517/518) for specifying build backends, build dependencies, and project metadata.
Question 3: Which Python built-in module provides support for reading and writing configuration files in INI format?
- json
- yaml
- configparser (Correct answer)
- toml
Correct answer: configparser
The `configparser` module reads and writes configuration files using INI-style syntax with sections and key-value pairs.
Question 4: What does `sys.path.insert(0, '/my/module/path')` accomplish?
- Appends a directory to the end of the module search path
- Sets the only search path Python will use
- Prepends a directory so Python searches it first (Correct answer)
- Permanently saves a path to site-packages
Correct answer: Prepends a directory so Python searches it first
Inserting at index 0 places the directory at the front of `sys.path`, giving it the highest search priority.
Question 5: In a virtual environment created with `venv`, where are installed packages stored?
- In the system site-packages
- In the user's home directory
- In the `Lib/site-packages` subdirectory of the venv folder (Correct answer)
- In `/usr/local/lib/python`
Correct answer: In the `Lib/site-packages` subdirectory of the venv folder
A venv maintains its own isolated `Lib/site-packages` directory separate from the global Python installation.
Question 6: Which command generates a `requirements.txt` file listing all currently installed packages and their versions?
- pip list > requirements.txt
- pip freeze > requirements.txt (Correct answer)
- pip export requirements.txt
- pip save requirements.txt
Correct answer: pip freeze > requirements.txt
`pip freeze` outputs installed packages in `name==version` format, suitable for use in `requirements.txt`.
Question 7: What happens when you run `python -m module_name` instead of importing a module?
- Python imports the module without executing it
- Python executes the module's `__main__` block as a script (Correct answer)
- Python only checks syntax without running code
- Python runs the module in a sandboxed environment
Correct answer: Python executes the module's `__main__` block as a script
The `-m` flag locates the named module and executes it as a script, triggering the `if __name__ == '__main__':` block.
Which pip command installs a package in 'editable' (development) mode from a local directory?