r/PythonLearning • • 22d ago

Discussion How much useful you found the lazy import in Python (v3.15)

lazy import pandas as pd

lazy from pathlib import Path

1 Upvotes

2 comments sorted by

1

u/Sea-Ad7805 22d ago

If you don't actually use say Pandas in a particular run of your program, you don't import it unnecessarily so your program is faster. If you do use it in each run lazy makes no difference, except it gets imported a bit later.

1

u/Atmosck 20d ago

For some of my larger projects I write typer CLIs and the new lazy imports have allowed me to simplify a fair bit. Previously I had a lot of function-local or type checking-only imports so that when you ran some-cli --help it was instant instead of getting bogged down by importing heavy dependencies.