paths.py - replacing space with slash+space
See original GitHub issueHi!
First of all, thanks for the library. Very useful! Second, I wanted to ask you why do you replace space with slash+space in paths.py? Is this a bug or something you’ve done on purpose?
imagePath = os.path.join(rootDir, filename).replace(" ", "\\ ")
PS: I’m using Windows and Python3.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Replacing everything with a backslash till next white space
which I want to remove from my string. I am using the regular expression based replace function in Python: udpated = re.sub(r'/\fs\d ...
Read more >How To Deal With Spaces in Paths on Mac and Linux - Medium
Method 2: Escaping Spaces With Backslash. A second, more “hardcore” method to ignore spaces uses what are called escape characters. Escape ...
Read more >Replace Forward Slash With Backslash in Python - Codeigo
A forward-slash (/) in a Python string can be replaced by a backslash (\) using the String replace() function, translate() method, ...
Read more >Sed replace space with backslash space (Bash) - Super User
Save this question. Show activity on this post. I'm trying to replace every space in this text file with a backslash space.
Read more >Replace space with new line - Unix & Linux Stack Exchange
Use the tr command echo "/path/to/file /path/to/file2 /path/to/file3 /path/to/file4 /path/to/file5" \ | tr " " "\n".
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s not a bug. It’s to escape file paths that have spaces in them. If you’re on a Unix machine try to auto-tab complete a file path that has spaces in them.
It will change:
$ cd Foo Bar
To:
$ cd Foo\ Bar
There’s no reason to manually add the slash in there with that
replace
operation. os.path handles that for you automatically. For example, this works fine (assuming the directory and file exist):results in
I don’t have a Windows computer to test that on, but according to the docs it should be fine. If you were targeting only python 3.4+ you could use the pathlib module instead.