python replace single backslash with double backslash [duplicate]

No need to use str.replace or string.replace here, just convert that string to a raw string: >>> strs = r”C:\Users\Josh\Desktop\20130216″ ^ | notice the ‘r’ Below is the repr version of the above string, that’s why you’re seeing \\ here. But, in fact the actual string contains just ‘\’ not \\. >>> strs ‘C:\\Users\\Josh\\Desktop\\20130216’ >>> … Read more

Why are the backslash and semicolon required with the find command’s -exec option?

The backslash before the semicolon is used, because ; is one of list operators (or &&, ||) for separating shell commands. In example: command1; command2 The find utility is using ; or + to terminate the shell commands invoked by -exec. So to avoid special shell characters from interpretation, they need to be escaped with … 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

Why do backslashes appear twice?

What you are seeing is the representation of my_string created by its __repr__() method. If you print it, you can see that you’ve actually got single backslashes, just as you intended: >>> print(my_string) why\does\it\happen? The string below has three characters in it, not four: >>> ‘a\\b’ ‘a\\b’ >>> len(‘a\\b’) 3 You can get the standard … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)