> For the complete documentation index, see [llms.txt](https://gromet.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gromet.gitbook.io/docs/basics/outputs.md).

# Outputs

To save files from your Python script and make them accessible to the user, simply write files into a special folder named `'OUTPUT_DIR'`. This folder is handled automatically by the system and is replaced at runtime with the appropriate path on the user's machine.

***

### 🧹 How It Works

The system uses a placeholder string `'OUTPUT_DIR'` in your Python code, and automatically replaces it with the actual output directory path when the script runs.

After execution, the system moves any files written to that directory into the user's configured output location.

***

### ✅ Example Usage

```python
import os
import pandas as pd

def main(input_file):
    """
    Reads a CSV file, creates the output directory if needed, 
    and saves the DataFrame as an Excel file inside the output directory.

    Parameters:
    -----------
    input_file : str
        Path to the input CSV file.
    """
    df = pd.read_csv(input_file)

    output_dir = "OUTPUT_DIR"
    os.makedirs(output_dir, exist_ok=True)

    output_file = os.path.join(output_dir, "results.xlsx")
    df.to_excel(output_file, index=False)

```

> ℹ️ You do **not** need to pass `OUTPUT_DIR` as a parameter to `main()`.\
> The system replaces it with the actual output path automatically.

***

### 🛠️ Rules and Tips

* ✅ Use the **exact string** `'OUTPUT_DIR'` (in single or double quotes) in your script.
* ❌ **Do not** define `OUTPUT_DIR` as a Python variable — it’s not a variable, it’s a placeholder string.
* ♻️ The replacement is handled **before** the script runs.
* 📁 All files inside the `OUTPUT_DIR` folder will be automatically moved to the final output location (specified in system settings) after execution.

***

### 💡 Behind the Scenes

Here's what happens under the hood:

1. Before running your script, the system searches for the string `'OUTPUT_DIR'` in your code.
2. If found, it replaces it with the actual `outputDir` path (e.g., `/Users/wallace/Documents/ScriptOutput/`).
3. After the script completes, it moves all files from the temporary output folder into the specified directory.
4. You’ll see a confirmation message like:

```markup
[success] Files saved to OUTPUT_DIR
```
