# 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gromet.gitbook.io/docs/basics/outputs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
