> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Structuring Your First Multi-File Python Project

> Organize a Python sales analysis project with separate folders for code, data, and output — the same layout professionals use every day.

Writing all your Python in a single file is fine for small experiments, but real projects grow quickly and need a structure that keeps things findable. Separating your source code, raw data files, and generated outputs into dedicated folders means you always know where to look — and so does anyone else who picks up your project. In this page, you'll set up a simple but professional layout for a sales analysis project inside your existing workspace.

## Organize your workspace

You already have a `python-for-ai` workspace from earlier in the course. Open it in VS Code and add a dedicated project folder with this layout:

```text theme={null}
python-for-ai/
├── hello.py                 # Your existing practice file
└── sales-analysis/          # New project folder
    ├── data/                # CSV files and raw input data
    └── output/              # Generated reports and results
```

<Tip>
  Create folders in VS Code by right-clicking in the Explorer panel and selecting **New Folder**, or by clicking the new-folder icon at the top of the Explorer pane.
</Tip>

## Create the data file

Inside `sales-analysis/data/`, create a file called `sales.csv` with the following content:

```csv theme={null}
date,product,quantity,price
2024-01-01,Laptop,2,999.99
2024-01-01,Mouse,5,29.99
2024-01-02,Keyboard,3,79.99
2024-01-02,Monitor,1,299.99
2024-01-03,Laptop,1,999.99
2024-01-03,Mouse,10,29.99
2024-01-04,Keyboard,2,79.99
2024-01-05,Monitor,2,299.99
```

<Note>
  Copy and paste this data directly into a new file. Make sure the file extension is `.csv`, not `.txt` — VS Code may try to add `.txt` if you're not careful.
</Note>

## Understanding file paths in your project

When your script runs, Python looks for files relative to the folder it's running from. If you keep your script in the `sales-analysis/` folder, these paths will work:

```python theme={null}
# Paths are relative to where your script lives
"data/sales.csv"        # The CSV file in the data subfolder
"output/report.json"    # Where to write results

# Your layout makes this straightforward:
# python-for-ai/
#   └── sales-analysis/
#       ├── analyzer.py     ← script runs from here
#       ├── data/sales.csv  ← data is here
#       └── output/         ← results go here
```

## Create your first script

In the `sales-analysis/` folder (not inside a subfolder), create `analyzer.py`:

```python theme={null}
import os

# Confirm you're running from the right place
print("Current directory:", os.getcwd())

# Verify the data file is where you expect it
data_path = "data/sales.csv"
if os.path.exists(data_path):
    print(f"✅ Found {data_path}")
else:
    print(f"❌ Cannot find {data_path}")
    print("Make sure you're running from the sales-analysis folder!")
```

## Running your code

VS Code gives you two convenient ways to run Python code:

### Option 1: The Play button

1. Open `analyzer.py` in VS Code
2. Click the ▶️ button in the top-right corner
3. Output appears in the terminal below

### Option 2: Interactive mode (recommended for learning)

1. Open `analyzer.py` in VS Code
2. Place your cursor on any line (or select a block)
3. Press **Shift + Enter**
4. The code runs in an interactive window and you see results immediately

<Tip>
  Interactive mode lets you run code line by line and inspect variables as you go. It's excellent for understanding what each step does and debugging as you write.
</Tip>

<Note>
  Keeping `analyzer.py` at the top of your project folder — alongside `data/` and `output/` — means file paths stay simple and consistent whether you use the Play button or interactive mode.
</Note>

## Best practices

1. **Keep data separate** — Never mix your Python scripts and your data files in the same folder
2. **Use clear names** — `data/` for inputs, `output/` for results makes the project self-documenting
3. **Put scripts at the project root** — Your main script should sit at the same level as `data/` and `output/`
4. **Test incrementally** — Use Shift + Enter to run and verify each section as you write it

<Card title="Python paths" icon="arrow-right" href="/practical-python/python-paths">
  Learn how Python finds your files and imports
</Card>
