Python Forum
OSX: copied path has escape character
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OSX: copied path has escape character
#1
On OSX, copied path has backslash character to escape spaces in directory name.

e.g. /Users/ronsair/Downloads/test\ -\ folder

os.path.exists(<path above>) returns false.

Do I need to remove escape character, or there is a more elegant way to do this?
Reply
#2
Is the actual path: /Users/ronsair/Downloads/test/folder?
or /Users/ronsair/Downloads/test-folder?
on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
Reply
#3
I don't know if this is the best, considering cross-platform compatibility. But I'm going with this.
path = path.strip().replace('\\', '')
Reply
#4
(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
It's
test[space]-[space]folder

(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
(Mar-14-2018, 05:08 PM)ronjan Wrote:
(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
It's test[space]-[space]folder
(Mar-14-2018, 05:08 PM)ronjan Wrote:
(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
It's test[space]-[space]folder

Screenshots:
Directory:
https://drive.google.com/file/d/1nl735uz...sp=sharing
Issue:
https://drive.google.com/file/d/1IMZTXN7...sp=sharing
Reply
#5
I figured out that, the issue highlighted is related more to OS behaviour.

I had been using the advantage of OSX, that when you copy [Cmd + C] a file and directory and paste it in terminal, the result is the absolute path, but with escape sequence if required. May be this is not the best way if you really want to copy the path. To copy the path, in the context menu, press [option] to switch to 'Copy ... as Pathname'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I handle escape character in parameter arguments in Python? JKR 6 1,115 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
  use of escape character in re.sub and find WJSwan 1 904 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  Escape indentation Frankduc 11 3,052 Jan-31-2022, 02:41 PM
Last Post: Frankduc
  add Escape charcters in string GrahamL 3 1,159 Jan-20-2022, 01:15 PM
Last Post: GrahamL
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,192 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Why changing data in a copied list changes the original list? plumberpy 3 2,219 Aug-14-2021, 02:26 AM
Last Post: plumberpy
  [solved] unexpected character after line continuation character paul18fr 4 3,378 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  Escape Single quotation between each content tag usman 3 2,781 May-02-2021, 03:32 PM
Last Post: snippsat
  DIY Escape Room for fun StannemanPython 1 2,293 Feb-17-2021, 10:53 PM
Last Post: maurom82
  super newbie question: escape character tsavoSG 3 2,426 Jan-13-2021, 04:31 AM
Last Post: tsavoSG

Forum Jump:

User Panel Messages

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