0

Don't suggest os.path.join since it does something strange

import os.path
base = "api/v1"
tail = "/employees"
os.path.join(base, tail)
'/employees'

I need function that really joins the parts of the path.

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 3
    Remove the `/` from `/employees`. A leading `/` is treated as the root directory, so it started over from scratch. – John Gordon Mar 14 '23 at 22:44
  • It doesn't do "something strange", it does exactly what it is supposed to do. A path that says `/employees` means "no matter where you are at this point, ignore all of that, start over at the root of the file system, and go into the employees folder". If you just wanted "go into the employees folder from where you are now", that is written `employees`, without a `/` at the front. – Karl Knechtel Apr 10 '23 at 03:04

1 Answers1

1

You can basically use the plus sign and save the result into a variable:

base = "api/v1"
tail = "/employees"
path = base + tail
Jan
  • 50
  • 6