POC Implementation & Configuration 3 — Questions and Answers
Question 1: What does the `PYTHONPATH` environment variable control?
- The location of the Python executable
- Additional directories prepended to `sys.path` for module searching (Correct answer)
- The version of Python to use
- The output directory for compiled `.pyc` files
Correct answer: Additional directories prepended to `sys.path` for module searching
`PYTHONPATH` is a colon-separated list of directories that Python prepends to `sys.path` before the interpreter starts.
Question 2: Which `setup.py` command builds a source distribution archive?
- python setup.py build
- python setup.py sdist (Correct answer)
- python setup.py dist
- python setup.py package
Correct answer: python setup.py sdist
`python setup.py sdist` creates a source distribution tarball (`.tar.gz`) in the `dist/` directory.
Question 3: What is the role of `__init__.py` in a Python package directory?
- It stores package documentation
- It marks the directory as a Python package and runs on import (Correct answer)
- It defines the package version only
- It is required only for Python 2 compatibility
Correct answer: It marks the directory as a Python package and runs on import
`__init__.py` signals to Python that the directory is a package and its code runs when the package is first imported.
Question 4: Which approach correctly reads a value from an environment variable with a fallback default in Python?
- os.env.get('KEY', 'default')
- os.environ.get('KEY', 'default') (Correct answer)
- env.get('KEY', 'default')
- os.getenv_default('KEY', 'default')
Correct answer: os.environ.get('KEY', 'default')
`os.environ.get('KEY', 'default')` returns the environment variable value or 'default' if the key is absent.
Question 5: In Python packaging, what does a `MANIFEST.in` file specify?
- The list of Python files to compile
- Additional files to include in source distributions (Correct answer)
- Installed console scripts and entry points
- Test discovery configuration
Correct answer: Additional files to include in source distributions
`MANIFEST.in` uses directives like `include` and `recursive-include` to add non-Python files (docs, data) to a source distribution.
Question 6: What is the effect of setting `PYTHONDONTWRITEBYTECODE=1` in the environment?
- Python skips syntax checking
- Python does not write `.pyc` bytecode cache files to disk (Correct answer)
- Python disables the import system
- Python runs in interpreted-only mode without optimization
Correct answer: Python does not write `.pyc` bytecode cache files to disk
Setting this variable prevents Python from creating `__pycache__` directories and `.pyc` files during import.
Question 7: Which `pip` flag installs a package without its dependencies?
- --no-requires
- --skip-deps
- --no-deps (Correct answer)
- --ignore-dependencies
Correct answer: --no-deps
`pip install --no-deps package` installs only the specified package while ignoring its declared dependencies.
What does the `PYTHONPATH` environment variable control?