Getting Started· 15 min

Running Scripts in VS Code

What you'll learn
  • Recognise the four command-line patterns used in the course
  • Run any script from the VS Code integrated terminal
  • Use --help to discover what a script needs
  • Debug a script with breakpoints and the Run button confidently

This page walks you through running every kind of script you will meet in the course — from a plain "no arguments" script to ones that need --prompt, --image, or multiple subcommands. Once you understand these four patterns you can run any exercise on your own.

Before you start
Make sure you have completed VS Code Setup and selected the .venv interpreter. The prompt in the integrated terminal should start with (.venv).

The basic workflow (memorise this)

  1. Open the session folder in VS Code (File → Open Folder → Session1, Session5, or Session6).
  2. Select the .venv interpreter if prompted (bottom-right status bar).
  3. Open the integrated terminal (Ctrl+` or View → Terminal).
  4. Confirm the prompt starts with (.venv).
  5. Type the python command for the exercise and hit Enter.

Pattern 1 — Script with no arguments

The simplest case. You just run it and read the output. Example: Session 5 script 01.

$ python 01_plain_response_basics.py
Shortcut: the Run button
For scripts that take no arguments you can also just click the ▶ triangle at the top-right of the VS Code editor — it does exactly the same thing.

Pattern 2 — Script with a --prompt argument

Most Session 1 text-generation scripts take a --prompt flag. The value is a string — wrap it in double quotes so the shell sends the whole sentence as one argument.

$ python src/01_text_basic.py --prompt "Give me 3 startup ideas for students"
Forgetting the quotes
python src/01_text_basic.py --prompt Give me 3 ideas will fail — the shell thinks "me", "3", and "ideas" are separate arguments. Always quote multi-word prompts.

Change the text inside the quotes and run again. Same script, different output. That is the whole point of these exercises — they are little playgrounds.

Pattern 3 — Script with multiple arguments

Some scripts take more than one flag. Vision and comparison exercises are a good example — they want a file path plus a question.

$ python src/06_image_analysis_basic.py --image assets/sample1.png --question "What do you see?"
$ python src/07_image_analysis_compare.py --image1 assets/a.png --image2 assets/b.png
Relative paths
assets/sample1.png is relative to the folder you ran the command from. If you get "file not found", check that your terminal is inside Session1 (pwd / cd to verify).

Pattern 4 — Script with subcommands

Session 1 script 10 is a mini CLI with four subcommands: summarize, ask-image, make-poster, speak. Pick one and add its required flags.

$ python src/10_cli_mini_app.py summarize --file notes.txt
$ python src/10_cli_mini_app.py ask-image --image assets/sample1.png --question "Describe this"
$ python src/10_cli_mini_app.py make-poster --prompt "Workshop poster for AI beginners"
$ python src/10_cli_mini_app.py speak --text "Class completed successfully"
How to discover what a script needs
Run the script with --help. It will print all available flags and subcommands automatically, because the scripts use argparse.
$ python src/10_cli_mini_app.py --help

Where do output files go?

Scripts that generate images, audio, or data write to an output/ folder inside the session. Look in the VS Code file explorer after the run — new files appear automatically.

  • Session 1 H8 image generation → output/generated.png
  • Session 1 H9 text-to-speech → output/speech.mp3
  • Session 1 H11 story pipeline → output/story_pipeline/scenes.json + audio/ + images/
Listen to the mp3 or view the png
Right-click the file in VS Code's explorer and choose "Reveal in Finder" (macOS) or "Reveal in File Explorer" (Windows). Double-click to open in your default viewer.

Debugging a script (when something breaks)

  1. Click the left margin next to any line to set a breakpoint (red dot).
  2. In the terminal type: python -m debugpy --listen 5678 --wait-for-client src/01_text_basic.py --prompt "hello" — OR easier, press F5 and choose "Python File".
  3. Execution pauses at your breakpoint. Inspect variables in the left Debug panel.
  4. Use F10 to step over, F11 to step into, and F5 to continue.
F5 with CLI arguments
If your script needs --prompt, create a tiny launch config at .vscode/launch.json — or simpler, just run it in the terminal and set a breakpoint. The Python extension shows the same Debug panel when execution pauses.

Running the SAME script with different inputs

In the VS Code terminal press the Up arrow to recall your last command. Edit the text inside the quotes and hit Enter. This is the fastest way to iterate on prompts during the workshop.

Iterating fast
# Run 1
python src/01_text_basic.py --prompt "Write a haiku about the sea"

# Press Up arrow, edit the prompt
python src/01_text_basic.py --prompt "Write a haiku about a coffee shop"

# Up arrow again
python src/01_text_basic.py --prompt "Write a limerick about Python"

Things that will NOT work (and why)

Clicking Run on a script that needs --prompt
The Run button does not pass arguments. Scripts that require flags will print an "the following arguments are required" error. Use the terminal for those.
Running from the wrong folder
Always cd into the session folder first. Running python Session1/src/01_text_basic.py from the parent folder usually breaks relative imports like "from common import ..." — run it from inside Session1 instead.
(.venv) missing from the prompt
Your interpreter is wrong. Click the Python version in the bottom-right status bar and reselect the .venv one, then open a new terminal.

Cheat sheet — one command per exercise

Session 1
python src/01_text_basic.py --prompt "..."
python src/02_text_params_lab.py --prompt "..."
python src/03_prompt_roles.py --topic "..."
python src/04_no_memory_demo.py
python src/05_context_memory_demo.py
python src/06_image_analysis_basic.py --image assets/sample1.png --question "..."
python src/07_image_analysis_compare.py --image1 assets/a.png --image2 assets/b.png
python src/08_image_generation.py --prompt "..."
python src/09_text_to_speech.py --text "..."
python src/10_cli_mini_app.py <summarize|ask-image|make-poster|speak> ...
python src/11_story_scene_pipeline.py --storyline "..." --num_scenes 5
Session 5
# All Session 5 scripts run with no arguments — just the file name
python 01_plain_response_basics.py
python 02_json_mode_basics.py
# ... through 20_chat_completions_parse_refusal.py
Session 6
# Same pattern as Session 5, but from the scripts/ folder
python scripts/00a_openai_smoke_test.py
python scripts/01_model_init_and_params.py
# ... through 09_structured_output_json_schema.py
You can run every exercise on your own now
Know the four patterns, know --help, know how to recall commands with the Up arrow. That is 95% of what you need.