python replace backslashes to slashes

You can use the string .replace() method along with rawstring. Python 2: >>> print r’pictures\12761_1.jpg’.replace(“\\”, “https://stackoverflow.com/”) pictures/12761_1.jpg Python 3: >>> print(r’pictures\12761_1.jpg’.replace(“\\”, “https://stackoverflow.com/”)) pictures/12761_1.jpg There are two things to notice here: Firstly to read the text as a drawstring by putting r before the string. If you don’t give that, there will be a Unicode error … Read more

Why both clang and gcc only give a warning when there is a space after backslash if C standard says that whitespace is forbidden?

The compiler is allowed to extend the language as long as the document the change which gcc does in their docs in section 6.21 Slightly Looser Rules for Escaped Newlines. Recently, the preprocessor has relaxed its treatment of escaped newlines. Previously, the newline had to immediately follow a backslash. The current implementation allows whitespace in … Read more

sh read command eats backslashes in input?

Accrding to: http://www.vias.org/linux-knowhow/bbg_sect_08_02_01.html : -r If this option is given, backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a backslash-newline pair may not be used as a line continuation. It works on my machine. $ echo ‘\&|’ | while read -r in; do … Read more

So what IS the right direction of the path’s slash (/ or \) under Windows?

Windows is the bastard child of operating systems in this regard, but a lot of APIs will accept forward slashes as well. On Windows, a file path looks like this: C:\Users\jsmith\Documents\file.txt On a Unix-like system (including Mac OS X and Linux), the same path would look like this: /home/jsmith/Documents/file.txt A URL, standardized in RFC 1738, … Read more