I am unable to understand , how are we able to directly call load_workbook from openpyxl package. I went through the https://openpyxl.readthedocs.io/en/stable/api/openpyxl.html to understand . But I am unable to do so .
We are able to call the load_workbook function like this. Can somebody help me understand this. We are neither importing the module from the package nor we are importing the function from the package.module nor we are directly importing the package.module inside which openpyxl is defined. Does the root openpyxl package itself has the function defined in it?
import openpyxl as xl
xl.load_workbook()
If you would to inspect the __init__.py
of the packege you will find - amongst others - the following lines:
from openpyxl.workbook import Workbook
from openpyxl.reader.excel import load_workbook
Then, going to reader.excel.py
you will find the definition of load_workbook
:
def load_workbook(filename, read_only=False, keep_vba=KEEP_VBA,
data_only=False, guess_types=False, keep_links=True):
"""Open the given filename and return the workbook .....
This (I believe) is done by the authors to create a convenient interface for the users, as these are very common and basic functions. So instead of needing to do:
openpyxl.reader.excel.load_workbook()
You can just do:
openpyxl.load_workbook()