Skip to content
Start free

Absolute vs. relative path: where does a path start from?

Reach the same file with a full path and with a path counted from the folder you're in.

Free course. Your Maestro, an AI, .

There are two ways to give an address.

An absolute path starts at the root: C:\Users\ana\Documents\Informes\ventas_marzo.xlsx on Windows, or /Users/ana/Documents/Informes/ventas_marzo.xlsx on a Mac. It's like giving a full mailing address, with street, city, state and ZIP code: it works no matter where you read it from.

A relative path is counted from the folder you're in: Informes/ventas_marzo.xlsx, or ../notas.txt. It's like saying "second door on the right": it only helps if you know where to start counting. That starting folder has a name: the .

Two things to know for reading relative paths:

  • .. means the folder above. ../notas.txt means "go up one folder, and notas.txt is there." ../../ goes up two.
  • A bare name with nothing in front, like notas.txt, is looked for in the folder you're in.

Note: Where this course stops

How a Python program decides where to start counting a relative path has rules of its own, and they're covered in Python for Data People. Here, the idea is enough: a relative path is always counted from somewhere.

Try it

In this project, Ana left a note at informes/2026/leeme.txt. Your task:

  1. Go in with cd informes/2026 and check where you are with pwd.
  2. Read the note with cat leeme.txt. It gives you a relative path.
  3. Try that path from right there, with cat. Does it work?
  4. Also read cat ../../notas.txt. Before you hit Enter, predict: which file is that?
  5. Go back to the project folder with cd .. twice and try the note's path again. Does it still work?
  6. In abrir.py, put the path to that file counted from the project folder, and run python abrir.py from there. You've got it when it says it found the file in informes/2025 with 3 rows.

If something in step 5 doesn't add up, ask your Maestro why the path stopped working.

Before step 1, run python abrir.py from the project folder, just as it is. The path it starts with is the one from the note, and your terminal should reply with this:

Expected output
Nothing found at: ../2025/ventas_marzo.csvWhich folder is that path counted from?

Hang on to the program's question: the steps above answer it.

Your turn

From informes/2026, follow the relative path in the note leeme.txt. Then, from the project folder, put the path to that same file in abrir.py and run python abrir.py. You've got it when it says it found ventas_marzo.csv in informes/2025 with 3 rows of sales.

    Python 3.12· runs with your account

    The note's path wasn't wrong: it was counted from informes/2026. From the project folder, the same file is informes/2025/ventas_marzo.csv. One file, two different relative paths, depending on where you're standing. The absolute path, on the other hand, is only ever one.

    That explains a lot of "it opens for me but not for you": a relative path that works from one folder stops working when you use it from another.

    Which one should you use?

    Neither one always wins. It depends on who the address is for:

    • For someone else, or another computer. The absolute path goes through your home folder, which only exists on your computer, like you saw with Ana's path. The relative path only helps them if you say which folder it's counted from: "from the project folder, informes/2025/ventas_marzo.csv."
    • For a program on your computer. The absolute path is the safest bet, as long as the file doesn't move. The relative path works if the program and the data travel together in the same folder, like in this project, and you know which folder it runs from.
    • For you, in the terminal. The relative path is shorter. Before you use it, pwd tells you where it's counted from.

    Check yourself: A note says: the file is at ../2025/ventas_marzo.csv. It works when you're in informes/2026, but not when you're in the project folder. Why?