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
  • 28,235
  • 9
  • 60
  • 81

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
  • 191,408
  • 23
  • 240
  • 301
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.

Mojtaba Arezoomand
  • 2,140
  • 8
  • 23