-1

I am trying to change directory using a variable which contains a path but os.chdir changes the \ in the path to \ which makes it undreadable/undefined for the os module and crashes.

any ideas on how to overcome this please?[shot ][1]

  • 1
    It is bad to post code or data as pictures. There is no way to copy and paste a picture into a code editor. So it will be much harder, and thus less likely, for someone to help. To get the most out of the site it is important to [ask good questions](http://stackoverflow.com/help/how-to-ask), that includes creating a [Minimal, Complete, and Verifiable](http://stackoverflow.com/help/mcve) example. – Stephen Rauch May 06 '18 at 17:42

1 Answers1

2

Try to use raw strings when dealing with file paths.

BOOKING_DIR = r"path to your dir"
BcK
  • 2,548
  • 1
  • 13
  • 27
  • My path is stored in a variable and I can't use r with the name of the variable where the string is stored. – Mahmoud Yassine May 06 '18 at 18:00
  • In that case maybe try changing damn `backslashes` with `double backslashes`. Man, I couldn't write it with \`s haha. @MahmoudYassine – BcK May 06 '18 at 18:10
  • I did that but os.chdir made them 4 slashes ! – Mahmoud Yassine May 06 '18 at 18:20
  • Last thing that comes to my mind is, you can try to split the whole string by `\ ` and then join them with the `os.path.join()` @MahmoudYassine – BcK May 06 '18 at 20:15