Python Forum

Full Version: OSX: copied path has escape character
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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
I don't know if this is the best, considering cross-platform compatibility. But I'm going with this.
path = path.strip().replace('\\', '')
(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
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'.