Calls to Attributes of a Class - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Calls to Attributes of a Class (/thread-33401.html) |
Calls to Attributes of a Class - SKarimi - Apr-22-2021 how does a direct call to openpyxl.load_workbook work? According to OpenPyXL documentation, load_workbook is a submodule of a the subpackage reader i.e: openpyxl.reader.excel.load_workbook However a direct call to openpyxl.load_workbook works fine while using other submodules of openpyxl need the full callout. See below: Initially in my code I had: import openpyxl try: openpyxl.load_workbook(filename) except openpyxl.InvalidFileException as ife: print(ife)which gave me the following error: however, when I changed line 4 to:except openpyxl.utils.exceptions.InvalidFileException as ife:exception handling work without an error. Why full Callout required on one and not the other submodule? I could not find anything in the Documentation. RE: Calls to Attributes of a Class - buran - Apr-22-2021 it depends what names are available on top level >>> import openpyxl >>> dir(openpyxl) ['DEFUSEDXML', 'LXML', 'NUMPY', 'Workbook', '__author__', '__author_email__', '__builtins__', '__cached__', '__doc__', '__file__', '__license__', '__loader__', '__maintainer_email__', '__name__', '__package__', '__path__', '__spec__', '__url__', '__version__', '_constants', 'cell', 'chart', 'chartsheet', 'comments', 'compat', 'constants', 'descriptors', 'drawing', 'formatting', 'formula', 'load_workbook', 'open', 'packaging', 'pivot', 'reader', 'styles', 'utils', 'workbook', 'worksheet', 'writer', 'xml'] load_workbook is made available/is exposed on top levelHere is the __init__.py source codehttps://foss.heptapod.net/openpyxl/openpyxl/-/blob/branch/3.0/openpyxl/__init__.py In other words - it's a decision of the developer how to organise their code and what names to be exposed top level. RE: Calls to Attributes of a Class - buran - Apr-22-2021 Also, note that open is alias for load_workbook
RE: Calls to Attributes of a Class - SKarimi - Apr-22-2021 Thanks buran. Exactly what I was looking for. |