My Awesomest Network, Is it neccessary to import a main library in Python and then import every sublibrary in parallel or is the first operation enough?
A Python library is a collection of different modules with specialized functions. You don't need to import all modules (if a sublibrary is how you refer to a module).
You can:
- import library (bringing the namespace to your workspace, thus you can call any module with library.module syntax)
- from library import * (import all modules namespaces to your workspace, this could conflict with other functions/modules/methods)
- from library import module (importing only one module, avoiding load unnecessary modules to your workspace)
- from library import module.method.function (you can dig into the library's tree)
Also, you can assign an alias to libraries and modules, such as:
- import library as lib
- from library import module as mod
There are a few cases when you need to call a module even when you load the library that contains it, but it is not common
It is variable depending on your goal in short, import the parent library like pandas is enough to be able to access all pandas functions however you have to invoke the parent which is why you see import statements like
import pandas as pd
so then the syntax is just
pd.read_csv()
However, if I am not using the whole library and just need to use the single function you can just use the following syntax
from pandas import read_csv
However, in this specific example, there is really no difference in time or size but it its a good practice to only bring the functions you need in an effort to keep your scripts organized and to keep long-term maintenance simpler