string-interpolation

Python: format string with custom delimiters [duplicate]

a 夏天 提交于 2019-11-26 14:53:00
问题 This question already has answers here : How can I print literal curly-brace characters in python string and also use .format on it? (12 answers) Closed last year . EDITED I have to format a string with values from a dictionary but the string already contains curly brackets. E.g.: raw_string = """ DATABASE = { 'name': '{DB_NAME}' } """ But, of course, raw_string.format(my_dictionary) results in KeyErro. Is there a way to use different symbols to use with .format() ? This is not a duplicate of

PowerShell outputting array items when interpolating within double quotes

一个人想着一个人 提交于 2019-11-26 13:50:57
I found some strange behavior in PowerShell surrounding arrays and double quotes. If I create and print the first element in an array, such as: $test = @('testing') echo $test[0] Output: testing Everything works fine. But if I put double quotes around it: echo "$test[0]" Output: testing[0] Only the $test variable was evaluated and the array marker [0] was treated literally as a string. The easy fix is to just avoid interpolating array variables in double quotes, or assign them to another variable first. But is this behavior by design? EBGreen So when you are using interpolation, by default it

bash variable interpolation separate variables by a hyphen or underscore

倖福魔咒の 提交于 2019-11-26 12:48:42
问题 This is a simple script just to see if the file has been downloaded. On this script the find command always evaluated to zero - even if it didn\'t find anything. So I commented it out. on the filename=\"day_CTRwFEES_hoo01M_\" I had to add an underscore to the end of the filename. Using an underscore $filename_$yesterday.CSV to separate the two did not work. - I had to take out the underscore, add it to the filename and then combine the variables to make it work like this - $filename$yesterday

PHP variable interpolation vs concatenation [duplicate]

ぐ巨炮叔叔 提交于 2019-11-26 12:27:07
问题 This question already has an answer here: Should I use curly brackets or concatenate variables within strings? 3 answers What is the difference between the two following methods (performance, readability, etc.) and what do you prefer? echo \"Welcome {$name}s!\" vs. echo \"Welcome \".$name.\"!\"; 回答1: Whatever works best for you works... But if you want to go for speed use this: echo 'Welcome ', $name, '!'; The single quotes tell PHP that no interpretation is needed, and the comma tells PHP to

String variable interpolation Java [duplicate]

血红的双手。 提交于 2019-11-26 12:03:02
问题 This question already has an answer here: How to format strings in Java 6 answers String building in Java confounds me. I abhore doing things like: url += \"u1=\" + u1 + \";u2=\" + u2 + \";u3=\" + u3 + \";u4=\" + u4 + \";\"; url += \"x=\" + u1 + \";y=\" + u2 + \";z=\" + u3 + \";da1=\" + u4 + \";\"; url += \"qty=1;cost=\" + orderTotal + \";ord=\" + orderId + \"?\"; Or, using StringBuilder, something like this: url.append(\"u1=\"); url.append(u1); url.append(\";u2=\"); url.append(u2); url

Using a Variable (PowerShell) inside of a command

我只是一个虾纸丫 提交于 2019-11-26 11:35:51
问题 $computer = gc env:computername # Argument /RU \'$computer\'\\admin isn\'t working. SchTasks /create /SC Daily /tn \"Image Verification\" /ST 18:00:00 /TR C:\\bdr\\ImageVerification\\ImageVerification.exe /RU \'$computer\'\\admin /RP password Basically I need to provide the computer name in the scheduled task... Thank you in advance! 回答1: Single quoted strings will not expand variables in PowerShell. Try a double quoted string e.g.: "$computer\admin" 回答2: use the command 'hostname' to get the

String Interpolation vs String.Format

∥☆過路亽.° 提交于 2019-11-26 11:00:03
问题 Is there a noticable performance difference between using string interpolation: myString += $\"{x:x2}\"; vs String.Format()? myString += String.Format(\"{0:x2}\", x); I am only asking because Resharper is prompting the fix, and I have been fooled before. 回答1: Noticable is relative. However: string interpolation is turned into string.Format() at compile-time so they should end up with the same result. There are subtle differences though: as we can tell from this question, string concatenation

How can I manually interpolate string escapes in a Perl string?

半城伤御伤魂 提交于 2019-11-26 10:02:32
问题 In perl suppose I have a string like \'hello\\tworld\\n\' , and what I want is: \'hello world \' That is, \"hello\", then a literal tab character, then \"world\", then a literal newline. Or equivalently, \"hello\\tworld\\n\" (note the double quotes). In other words, is there a function for taking a string with escape sequences and returning an equivalent string with all the escape sequences interpolated? I don\'t want to interpolate variables or anything else, just escape sequences like \\x ,

Use YAML with variables

隐身守侯 提交于 2019-11-26 09:08:18
问题 Are variables within YAML files possible? For example: theme: name: default css_path: compiled/themes/$theme.name layout_path: themes/$theme.name In this example, how can theme: name: default be used in other settings? What is the syntax? 回答1: I had this same question, and after a lot of research, it looks like it's not possible . The answer from cgat is on the right track, but you can't actually concatenate references like that. Here are things you can do with "variables" in YAML (which are

How to postpone/defer the evaluation of f-strings?

ⅰ亾dé卋堺 提交于 2019-11-26 08:56:39
问题 I am using template strings to generate some files and I love the conciseness of the new f-strings for this purpose, for reducing my previous template code from something like this: template_a = \"The current name is {name}\" names = [\"foo\", \"bar\"] for name in names: print (template_a.format(**locals())) Now I can do this, directly replacing variables: names = [\"foo\", \"bar\"] for name in names: print (f\"The current name is {name}\") However, sometimes it makes sense to have the