Reputation:
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'
Upvotes: 2
Views: 332
Reputation: 2380
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.
Upvotes: 0
Reputation: 198436
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.
Upvotes: 5