> For the complete documentation index, see [llms.txt](https://tvn.gitbook.io/test-automation-with-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tvn.gitbook.io/test-automation-with-python/python-for-test-automation/function/import-function-from-other-file.md).

# Import function from other file

Assuming we have a file named `my_module.py` that contains a function named `my_function`:

```python
# File: my_module.py

def my_function():
    print("Hello from my_function!")

```

We can import this function into another file using the `import` statement. Here's an example:

```python
# File: main.py

from my_module import my_function

# Call imported function
my_function()  # Output: Hello from my_function!

```

Import function from sub directory

````
```python
import sys
sys.path.append('./Basics/')
from Basics import calculator
calculator.demo(name="hado")

```
````

Import function from other directory

````
```python
import sys
sys.path.append('./Basics')
import calculator

calculator.giai_phuong_trinh_bac_2(1,1,1)
```
````
