# __init__.py

Assuming you have the following directory structure:

```python
models/
     |- engine/
               |-file_storage.py
     |-base_model.py
```

How can you import BaseModel class from base\_model.py in file\_storage.py?

There three ways do this

1. To import the `BaseModel` class from `base_model.py` into `file_storage.py`, you can use the following syntax:
    
    In `file_storage.py`:
    
    ```python
    from ..base_model import BaseModel
    ```
    
    Here's how it works:
    
    1. The double dot `..` is used to traverse up one level in the directory structure.
        
    2. `base_model` is the name of the Python module (file) without the `.py` extension.
        
    3. `BaseModel` is the name of the class you want to import from `base_model.py`.
        
    
    With this import statement, you can access the `BaseModel` class in `file_storage.py` and use it as needed.
    
2. Add the directory containing `base_model.py` to the Python path:
    
    In `file_storage.py`:
    
    ```python
    import sys
    sys.path.append('../')
    from base_model import BaseModel
    
    # Access the BaseModel class
    my_model = BaseModel()
    ```
    
    By adding the parent directory of `base_model.py` to the Python path, you can import the `BaseModel` class directly without the need for relative imports.
    
3. The third solution is a bit tricky
    
    ```python
    from models.base_model import BaseModel
    ```
    
    This woks, but the models directory must be a package(have an **\_\_init\_\_.py** file).
    
    Having an `__init__.py` file in a directory signifies that it is a package in Python. This file can be empty or can contain initialization code for the package. When Python encounters an `__init__.py` file in a directory, it recognizes that directory as a package and allows you to import modules or sub-packages from within that package.
    
    In the given directory structure:
    
    ```python
    models/
         |- __init__.py
         |- engine/
                   |-file_storage.py
         |-base_model.py
    ```
    
    If the `models` directory does not contain an `__init__.py` file, it is not recognized as a package. In that case, you cannot directly import modules or classes from that directory using the dot notation.
    
    However, if you add an empty `__init__.py` file in the `models` directory, it becomes a package, and Python treats it as a module that can be imported. The presence of the `__init__.py` file indicates that the directory should be treated as a package, allowing you to organize your code into modules and sub-packages.
    
    Once `models` is recognized as a package with the `__init__.py` file, you can use the import statement `from models.base_model import BaseModel` to import the `BaseModel` class from `base_model.py`. The dot notation (`models.base_model`) indicates the package name (`models`) and the module name (`base_model`) to import the desired class.
    
    In summary, the `__init__.py` file in a directory signals to Python that the directory is a package and enables you to use dot notation to import modules or classes from that package.
