0

I have a space in the path and I try to use \ , but when I print the path, it gives me two \ in output. How can we avoid double \ as I need this path later to access on shell file.

source_list = ["/media/aqeel/My\Book/2018","/media/aqeel/My\Book/2019", "/media/aqeel/My\Book/2020"]
print(source_list)
['/media/aqeel/My\\Book/2018', '/media/aqeel/My\\Book/2019', '/media/aqeel/My\\Book/2020']

the expected output should be like this

['/media/aqeel/My\Book/2018', '/media/aqeel/My\Book/2019', '/media/aqeel/My\Book/2020']

Later I want to use this file to use with bash file as given below

os.system(f"sh utils/Event2SAC.sh {'"source"'} {tar_base+'/'} 
Aqeel
  • 188
  • 1
  • 11
  • Check out [Escape Sequence](https://en.wikipedia.org/wiki/Escape_sequence). The \ must be \\ in order to avoid \B being interpreted as an escape sequence. As evidence of the problems arising from improper escape sequences: I had to edit this comment a few times in order to get it to render correctly, ultimately giving up on code blocks. – Michael Ruth Jul 29 '21 at 03:34
  • I used \\ but still, it gave the same output as above. – Aqeel Jul 29 '21 at 04:01
  • Your question asks "why." Is it the case that you also want to know how to get a specific output? If so, please update your question and include the expected output. – Michael Ruth Jul 29 '21 at 04:07
  • @MichaelRuth Thanks for the comment and suggestion. I updated the question and included the expected output – Aqeel Jul 29 '21 at 04:19
  • Does this answer your question? [In Python, how do I have a single backslash element in a list?](https://stackoverflow.com/questions/59460305/in-python-how-do-i-have-a-single-backslash-element-in-a-list) – Michael Ruth Jul 29 '21 at 04:25
  • @MichaelRuth thanks dear we do not need to change the space in path, it will works if use single quotation outside of the source name, for example, '''os.system(f"sh utils/Event2SAC.sh '{source}' {tar_base+'/'} ") – Aqeel Jul 29 '21 at 05:25

0 Answers0