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
#7
Yes I understand, but there's also another difference: you've add the "r" in front of the string to declare a "regular expression" whereas in my case I'm using a variale: how can I use a variable or how can I declare the variable as a regular expression?

path = 'D:\My Directory1\bin'
Var = r''+ path   #Var = r'' + str(path)
print("using replace", Var.replace('\\', '/'))
print("using replace with raw string", path.replace(r"\ "[0], "/"))
print("using regex", re.sub('\\\\', '/', path))
(obviously it does not work because of \b as it has ever been sugested)
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 paul18fr - Jul-21-2022, 01:29 PM

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,307 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  How could i change the python interpreter path of os.system() 12019202386 2 2,704 Sep-02-2020, 06:58 AM
Last Post: DeaD_EyE
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,596 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Deny backslash using regex JohnnyCoffee 1 1,758 Mar-18-2020, 10:21 PM
Last Post: snippsat
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,927 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  converting backslash codes Skaperen 4 5,606 Apr-21-2018, 04:07 AM
Last Post: Skaperen
  Reading and writing Windows filepath without treating backslash as escape character Dangthrimble 3 3,643 Dec-18-2017, 06:18 PM
Last Post: DeaD_EyE
  [split] Single slash syntax in file path aogata 3 4,692 Aug-09-2017, 04:50 PM
Last Post: snippsat
  Replace Single Backslash with Double Backslash in python saswatidas437 2 33,741 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