-3
path=os.path.join(BASE_DIR,'prueba.pdf')
print(path)
my_path=open(os.path.join(BASE_DIR,'prueba.pdf'), 'rb')

error

Why do the two backslashes appear?

  • 4
    [Please don't post screenshots of text](https://meta.stackoverflow.com/a/285557/354577). They can't be searched or copied and offer poor usability. Instead, paste the code as text directly into your question. If you select it and click the `{}` button or Ctrl+K the code block will be indented by four spaces, which will cause it to be rendered as code. – ChrisGPT was on strike Apr 30 '20 at 01:13
  • Because there is no such file in that directory , The error is self Explanatory – Ahmed Soliman Apr 30 '20 at 01:14
  • Does this answer your question? [Why do backslashes appear twice?](https://stackoverflow.com/questions/24085680/why-do-backslashes-appear-twice) – wjandrea Apr 30 '20 at 01:16
  • Is your question really about the backslashes, or about the exception you're getting from `open`? – Blckknght Apr 30 '20 at 01:17

1 Answers1

1

“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("\\")
"\"
michaeldel
  • 2,204
  • 1
  • 13
  • 19