0

i have some scripts that take as input one or multiple paths as on argument.

The script is run like that: myScript.py D:\Folder1,E:\OtherData\Files

In the script, i split the path arguments in the comma and i read the paths.

The problem is that Python adds a \r in the end of each path for no reason. So the script tries to read D:\Folder1\r and E:\OtherData\Files\r.

Why is this and how can i solve it?

Dimitrios
  • 33
  • 5
  • 1
    I've never seen Python add extraneous that weren't supposed to be there for no reason. Please add a [mcve] so we can see what you mean. – TigerhawkT3 Jan 30 '17 at 07:44
  • A comma (`,`) is a valid character in a file name. I advise to separate the filename by a space and put them in quotation marks if needed. This will make them separate items in `sys.argv`. – Klaus D. Jan 30 '17 at 07:47
  • This is might be the result of python and whatever program is launching it (presumably your shell) disagreeing on what operating system you're using. Python knows to strip `'\r\n'` from the arguments on Windows, and `'\n'` on Unixes, but if you're using something like Cygwin or MSYS or a version of python compiled either (and any other combination of Windows and Windows-ish software) that might result in one expecting the opposite. – Christian Reall-Fluharty Dec 03 '20 at 22:28

1 Answers1

0

There are many ways, here is one for example.

Replacing the relevant problematic string with an empty string:

paths= [x.rstrip() for x in paths_list]

The method rstrip() returns a copy of the string in which all chars have been stripped from the end of the string (default whitespace characters).

omri_saadon
  • 10,193
  • 7
  • 33
  • 58