backslash

python replace single backslash with double backslash

≯℡__Kan透↙ 提交于 2019-11-27 04:45:06
In python, I am trying to replace a single backslash ("\") with a double backslash("\"). I have the following code: directory = string.replace("C:\Users\Josh\Desktop\20130216", "\", "\\") However, this gives an error message saying it doesn't like the double backslash. Can anyone help? 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:\

CMake: how to get the backslash literal in Regexp replace?

泄露秘密 提交于 2019-11-27 03:55:38
问题 I am trying to replace forwardslashes with backslashes. To do that i have the following line of code: STRING(REGEX REPLACE "/" "\\" SourceGroup ${SourceGroupPath} ) SourceGroupPath = A/File/Path. SourceGroup is the variable to set the result to. The problem i am having is with, the "\\" part to the code. I have tried several ways to getting to use the backslash literal like "\\" and using unicode but nothing seems to work. The error i get in CMake is: CMake Error at CMakeLists.txt:41 (STRING)

Include header path change from Windows to Linux

◇◆丶佛笑我妖孽 提交于 2019-11-27 03:25:53
问题 I'm porting an application written in C++ from Windows to Linux. I have a problem with the header files path. Windows uses \ and Linux uses / . I am finding it cumbersome to change this in each and every source and header file. Is there some work around? 回答1: Always use forward slashes in #include paths. It is the compiler's job to map the path to whatever slash/directory scheme the underlying OS supports. 回答2: You people! Yes , you can, and should, always use forward slashes. I think the

Python: '#' Comments after backslash

江枫思渺然 提交于 2019-11-27 03:01:36
问题 This doesn't work: something = \ line_of_code * \ # Comment another_line_of_code * \ # Comment and_another_one * \ # Comment etc Neither does this: something = \ # Comment \ line_of_code * \ # Comment \ another_line_of_code * ... Neither does this: something = \ ''' Comment ''' \ line_of_code * \ ''' Comment ''' \ another_line_of_code * ... If there a way to make comments in the code broken into multiple lines? 回答1: Do it like that: a, b, c, d = range(1, 5) result = ( # First is 1 a * # Then

Why is '\x' invalid in Python?

痴心易碎 提交于 2019-11-27 02:06:05
问题 I was experimenting with '\' characters, using '\a\b\c...' just to enumerate for myself which characters Python interprets as control characters, and to what. Here's what I found: \a - BELL \b - BACKSPACE \f - FORMFEED \n - LINEFEED \r - RETURN \t - TAB \v - VERTICAL TAB Most of the other characters I tried, '\g', '\s', etc. just evaluate to the 2-character string of a backslash and the given character. I understand this is intentional, and makes sense to me. But '\x' is a problem. When my

Weird backslash substitution in Ruby

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:20:21
I don't understand this Ruby code: >> puts '\\ <- single backslash' # \ <- single backslash >> puts '\\ <- 2x a, because 2 backslashes get replaced'.sub(/\\/, 'aa') # aa <- 2x a, because two backslashes get replaced so far, all as expected. but if we search for 1 with /\\/ , and replace with 2, encoded by '\\\\' , why do we get this: >> puts '\\ <- only 1 ... replace 1 with 2'.sub(/\\/, '\\\\') # \ <- only 1 backslash, even though we replace 1 with 2 and then, when we encode 3 with '\\\\\\' , we only get 2: >> puts '\\ <- only 2 ... 1 with 3'.sub(/\\/, '\\\\\\') # \\ <- 2 backslashes, even

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

北城以北 提交于 2019-11-27 00:21:06
It seems Windows insists on writing a backslash \ in file paths, whereas .NET's URI class writes them with a slash / . Is there any right way, that is accepted even in the most primitive systems? And why is .NET's URI showing the other slash compared with the rest of Windows? A file path and a URI are different. \ is correct in a Windows file path and / is correct in a URI. So this file path: C:\Documents\Foo translates to this URI: file:///C:/Documents/Foo 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 issues in R using Windows (“Hex digits in character string” error)

主宰稳场 提交于 2019-11-26 23:41:10
I run R on Windows, and have a csv file on the Desktop. I load it as follows, x<-read.csv("C:\Users\surfcat\Desktop\2006_dissimilarity.csv",header=TRUE) but the R gives the following error message Error: '\U' used without hex digits in character string starting "C:\U" So what's the correct way to load this file. I am using Vista replace all the \ with \\ . it's trying to escape the next character in this case the U so to insert a \ you need to insert an escaped \ which is \\ Please do not mark this response as correct as smitec has already answered correctly. I'm including a convenience

How to replace a double backslash with a single backslash in python?

江枫思渺然 提交于 2019-11-26 22:57:46
问题 I have a string. In that string are double backslashes. I want to replace the double backslashes with single backslashes, so that unicode char codes can be parsed correctly. (Pdb) p fetched_page '<p style="text-align:center;" align="center"><strong><span style="font-family:\'Times New Roman\', serif;font-size:115%;">Chapter 0<\\/span><\\/strong><\\/p>\n<p><span style="font-family:\'Times New Roman\', serif;font-size:115%;">Chapter 0 in \\u201cDreaming in Code\\u201d give a brief description

How to escape the backslashes and the automatically generated escape character in file path in java

家住魔仙堡 提交于 2019-11-26 22:54:56
I have very small and simple problem but I am not getting solutions on it. Actually I am getting a CSV file path using file chooser. I am entering the data in this csv file in to database using load data local infile query. Suppose my entered file path is "C:\title.csv" When I put this string in to query the you will see the \t combination in the path. This \t which is actually part of the file path and not the escape character '\t'. But the java and mysql consider it as escape character. then I tried to replace '\' in the file path string with "\\" using following code line. String filepath=