2

I'm wondering about / in python.

I know that it divides two integers, but I've seen something like this

'NAME': BASE_DIR / 'db.sqlite3'
wjandrea
  • 23,210
  • 7
  • 49
  • 68

2 Answers2

5

Python allows defining the behaviour of operators when applied to custom classes using specially named methods ("dunders", from "double-underline"), as described here. The / operator's behaviour can be defined by .__truediv__(self, other) method. It is almost certainly the case here that BASE_DIR is an instance of pathlib.Path, which defines / as semantically equivalent to os.path.join for strings. You can read more here.

Amadan
  • 179,482
  • 20
  • 216
  • 275
0

BASE_DIR is pathlib.Path object which supports the / operator for joining paths. You need to either use / or use os.path.join if you use strings.

MojixCoder
  • 1,559
  • 6
  • 16