Know to work with classes and objects in python.
Classes vs Objects vs Methods
- Class is a blueprint of an object.
- Each class has its own attributes and methods (its behaviors).
- Many objects may have the same class. They have attributes and methods defined in the class.
Import local class
Suppose that we have a folders/files structure like below,
# ORIGINAL STRUCTURE popai/ processings/ a.py # contains class ABC test/ b.py lib/ c.py # contains class XYZ
# UPDATED STRUCTURE popai/ __init__.py processings/ __init__.py a.py # contains class ABC test/ __init__.py b.py lib/ c.py # contains class XYZ
We want import both classes
# b.py from popai.processings.a import ABC # a.py from popai.lib.c import XYZ
__init__.py like in the right box above.
Some errors may occur,
ValueError: attempted relative import beyond top-level package