backslash

Why isn't it possible to use backslashes in f-strings?

蹲街弑〆低调 提交于 2019-12-23 22:42:48
问题 In Python >=3.6, f-strings can be used as a replacement for the str.format method. As a simple example, these are equivalent: '{} {}'.format(2+2, "hey") f'{2+2} {"hey"}' Disregarding format specifiers, I can basically move the positional arguments of str.format inside braces in an f-string. Note specifically that I am allowed to just put str literals in here, although it may seem a bit unwieldy. There are however some limitations. Specifically, backslashes in any shape or form are disallowed

Replace double slashes to four slashes

徘徊边缘 提交于 2019-12-23 20:57:49
问题 I have char data type that contain a directory with double slashes. I want to replace the double slashes to four slashes so that my output will be double slashes. I had tried a lots of solutions, but nothing works. char *str = "C:\\Users\\user\\desktop"; for(int i = 0;i < strlen(str) ; i++) if(str[i] == '\\') str[i] =='\\\\'; The output of this code shows 'C:\Users\user\desktop'. 回答1: First off, since you're using c++, consider using std::string . Modifying a string literal is undefined

How can using Python backslash line continuation be subtly wrong?

六月ゝ 毕业季﹏ 提交于 2019-12-23 01:43:14
问题 This section of the Python docs describes a subtle error that can happen when using backslash line continuation, if you accidentally add a space after the backslash. It says, the following would be a syntax error (with a space after the backslash): if foo.bar()['first'][0] == baz.quux(1, 2)[5:9] and \ calculate_number(10, 20) != forbulate(500, 360): pass ...but that the next snippet would just be subtly wrong (with a space after the backslash): value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9

String replace with backslashes in Python

回眸只為那壹抹淺笑 提交于 2019-12-22 12:16:27
问题 I'm trying to do a simple replacement of " " with "\s" (the literal \s, not some sort of backslash escape). This is what I think should happen: >>> 'asdf hjkl'.replace(' ', '\s') 'asdf\shjkl' I did this: >>> 'asdf hjkl'.replace(' ', '\s') 'asdf\\shjkl' >>> 'asdf hjkl'.replace(' ', '\\s') 'asdf\\shjkl' Neither returns what I expected, and I can't for the life of me understand what's going on. What input do I have to use to get my expected output? 回答1: You're getting what you want. It just

Pycharm behaving strange with Git (Filename in tree entry contains backslash)

我的未来我决定 提交于 2019-12-22 11:33:41
问题 I just got a new laptop and wanted to clone my universities git repository with pycharm . Whenever I try to clone the repository, using either Git bash/GUI or Pycharm, it fails with the error, Filename in tree entry contains backslash: 'Aufgabe4a.py# coding=utf-8 ... Within the error is the complete content of the mentioned file. As this is the repo of my university, I can't just go and rename files that are not mine. The weird thing is, this doesn't happen on my desktop . I can clone the

Why does PyCharm use double backslash to indicate escaping?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 17:18:42
问题 For instance, I write a normal string and another "abnormal" string like this: Now I debug it, finding that in the debug tool, the "abnormal" string will be shown like this: Here's the question: Why does PyCharm show double backslashes instead of a single backslash? As is known to all, \' means ' . Is there any trick? 回答1: What I believe is happening is the ' in your c variable string needs to be escaped and PyCharm knows this at runtime, given you have surrounded the full string in " (You'll

Removing backslash from strings in R

╄→尐↘猪︶ㄣ 提交于 2019-12-20 03:36:08
问题 I want to remove list(\" and \") from strings such as list(\"TSPAN6\") and get TSPAN6 . I tried to do that with grep function, however I have problem with backslashes included the strings. I tried: gsub('list(\\"','', "list(\"TSPAN6\")", fixed=T) but it does not work?! I appreciate if you could help me. 回答1: Using one single gsub . x <- c("list(\"TSPAN6\")") x [1] "list(\"TSPAN6\")" gsub('list|[[:punct:]]', "", x) [1] "TSPAN6" 回答2: I found it: a <- gsub('list(\"','', "list(\"TSPAN6\")", fixed

Text replacement with backslash in a variable in Perl

醉酒当歌 提交于 2019-12-20 02:16:46
问题 How can I replace the backslash inside the variable? $string = 'a\cc\ee'; $re = 'a\\cc'; $rep = "Work"; #doesnt work in variable $string =~ s/$re/$rep/og; print $string."\n"; #work with String $string =~ s/a\\cc/$rep/og; print $string."\n"; output: a\cc\ee Work\ee 回答1: Because you're using this inside of a regex -- you probably want quotemeta() or \Q and \E (see perldoc perlre ) perl -E'say quotemeta( q[a/asf$#@ , d] )' # prints: a\/asf\$\#\@\ \,\ d # Or, with `\Q`, and `\E` $string =~ s/\Q

Different behaviours of treating \ (backslash) in the url by FireFox and Chrome

假装没事ソ 提交于 2019-12-19 05:22:25
问题 BACKGROUND According to my experience when my ubuntu workstation is configured on domain with active directory, the user name created for me was according to the following pattern. domain_name\user_name Using the userdir extensions of apache on linux will require to use user name in the URL in order to access public_html in the home directory. http://localhost/~domain_name\user_name PROBLEM A: Chrome converts all the backslash ' \ ' characters in the URL to forward slash ' / ' and the

Windows shell string operations (changing backslash to slash)

≡放荡痞女 提交于 2019-12-18 10:55:07
问题 I need to write a script that takes the current path (%~dp0), transforms backslashes into forward slashes and passes it further to some command. Due to the environment I'm working in the only option that I have is windows shell (not Powershell where the issue would not a problem). Is it even possible to do that? 回答1: The set command has a substitution feature: set a=C:\test\dir set a=%a:\=/% echo %a% Results in: C:/test/dir 来源: https://stackoverflow.com/questions/2903416/windows-shell-string