path=os.path.join(BASE_DIR,'prueba.pdf')
print(path)
my_path=open(os.path.join(BASE_DIR,'prueba.pdf'), 'rb')
Why do the two backslashes appear?
path=os.path.join(BASE_DIR,'prueba.pdf')
print(path)
my_path=open(os.path.join(BASE_DIR,'prueba.pdf'), 'rb')
Why do the two backslashes appear?
“Double backslashes” appear because they are getting escaped. Windows paths use backslash (\
) as separator, but these are the escape character. What you are seeing in the traceback is the __repr__
of the BASE_DIR
string, which shows escaped characters (e.g. \\
) instead of the real characters (e.g. \
).
Here is an example in the Python interactive interpreter:
>>> "\\"
"\\"
>>> print("\\".__repr__())
"\\"
>>> print(repr("\\"))
"\\"
# this time we are not calling repr
>>> print("\\")
"\"