bhylu.com

Advertisements

Built-in Modules

Modules provide namespaces and reusable code. Distinguish modules shipped with Python from external distributions installed into your environment.

Understand the idea

The standard library includes math, statistics, pathlib, json, datetime, collections, and many others. Technically, built-in modules are a smaller implementation category than the whole standard library. importlib can inspect availability without requiring you to guess from a package name. Keep module names in your project from shadowing standard-library imports.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

A worked example

Python

import importlib.util
print(importlib.util.find_spec("json") is not None)
print(importlib.util.find_spec("math") is not None)

Read the result

Both checks are True in the supported runtime.

Try one change

Compare the installed distribution name scikit-learn with the import namespace sklearn.