Python Forum
change backslash into slash in a path
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change backslash into slash in a path
#2
Your problem starts with
Path = 'D:\My Directory1\bin'
Path does not contain the string "\b". "\b" is an escape sequence for the back space character, so "Directory1\bin" is really "Directoryin". The substitution of "\b" with backspace has already happened before you try to replace or substitute. Your attempts fail because there is no backslash to replace.

To fix the problem you have to fix the str. Use "\\" if you want the str to contain "\" as a character, or use raw strings.
path = r'D:\My Directory1\bin'
path = 'D:\\My Directory1\\bin'
Of possible interest "\M" is just a str with a backslash followed by "M". This is because "\M" is not a recognized escape sequence like \b, \f, \n, \o, \r, \t, \u, \x
Reply


Messages In This Thread
change backslash into slash in a path - by paul18fr - Jul-21-2022, 08:50 AM
RE: change backslash into slash in a path - by deanhystad - Jul-21-2022, 11:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,322 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  How could i change the python interpreter path of os.system() 12019202386 2 2,724 Sep-02-2020, 06:58 AM
Last Post: DeaD_EyE
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,608 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Deny backslash using regex JohnnyCoffee 1 1,767 Mar-18-2020, 10:21 PM
Last Post: snippsat
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,938 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  converting backslash codes Skaperen 4 5,614 Apr-21-2018, 04:07 AM
Last Post: Skaperen
  Reading and writing Windows filepath without treating backslash as escape character Dangthrimble 3 3,659 Dec-18-2017, 06:18 PM
Last Post: DeaD_EyE
  [split] Single slash syntax in file path aogata 3 4,704 Aug-09-2017, 04:50 PM
Last Post: snippsat
  Replace Single Backslash with Double Backslash in python saswatidas437 2 33,832 Mar-19-2017, 10:48 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020