string-interpolation

Does Python do variable interpolation similar to “string #{var}” in Ruby?

狂风中的少年 提交于 2019-11-27 11:07:11
问题 In Python, it is tedious to write: print "foo is" + bar + '.' Can I do something like this in Python? print "foo is #{bar}." 回答1: Python 3.6+ does have variable interpolation - prepend an f to your string: f"foo is {bar}" For versions of Python below this (Python 2 - 3.5) you can use str.format to pass in variables: # Rather than this: print("foo is #{bar}") # You would do this: print("foo is {}".format(bar)) # Or this: print("foo is {bar}".format(bar=bar)) # Or this: print("foo is %s" % (bar

How to solve “String interpolation produces a debug description for an optional value; did you mean to make this explicit?” in Xcode 8.3 beta?

放肆的年华 提交于 2019-11-27 09:55:53
问题 Since beta 8.3, zillions warnings "String interpolation produces a debug description for an optional value; did you mean to make this explicit?" appeared in my code. For example, the warning popped in the following situation up, where options could lead to nil: let msg = "*** Error \(options["taskDescription"]): cannot load \(sUrl) \(error)" As previously designed, it was ok for me (and the compiler) the optionals to be interpolated as 'nil'. But compiler changed its mind. What the compiler

String interpolation in YAML

感情迁移 提交于 2019-11-27 09:43:14
In Perl I can do something like the following: my $home = "/home"; my $alice = "$home/alice"; Can I do something like the following in YAML: Home: /home Alice: $Home/alice So "Alice" is effectively /home/alice in the end? Paul Fioravanti Unfortunately, you're out of luck. To do what you want you'd need to pass in $home from a view file (or wherever) and interpolate it in your yaml entry, which could possibly look something like: Alice: ! '%{home}/Alice' See this StackOverflow Q&A for the detailed answer to pretty much exactly your question. You should use ERB template. you can write like

String interpolation doesn't work with .NET Framework 4.6

允我心安 提交于 2019-11-27 06:34:26
问题 I just installed the .NET Framework 4.6 on my machine and then created a ConsoleApplication targeting .NET Framework 4.6 with Visual Studio 2013. I wrote the following in the Main method: string test = "Hello"; string format = $"{test} world!"; But this does not compile. Doing the same in Visual Studio 2015 works. Why? 回答1: String interpolation is a C# 6.0 feature, not one of .NET Framework 4.6. VS 2013 doesn't support C# 6 but VS 2015 does. 回答2: String interpolation is indeed a C# 6.0

String variable interpolation Java [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-11-27 06:30:54
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.append(";u3="); url.append(u3); url.append(";u4="); url.append(u4); url.append(";"); url.append("x="); url.append(u1); url.append(";y=");

Python string interpolation implementation

China☆狼群 提交于 2019-11-27 06:08:37
问题 [EDIT 00]: I've edited several times the post and now even the title, please read below. I just learned about the format string method, and its use with dictionaries, like the ones provided by vars() , locals() and globals() , example: name = 'Ismael' print 'My name is {name}.'.format(**vars()) But I want to do: name = 'Ismael' print 'My name is {name}.' # Similar to ruby So I came up with this: def mprint(string='', dictionary=globals()): print string.format(**dictionary) You can interact

bash variable interpolation separate variables by a hyphen or underscore

不想你离开。 提交于 2019-11-27 05:39:16
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 . How could I get it to work without adding the underscore to the end of the variable $filename ? #!/bin

Multiline C# interpolated string literal

岁酱吖の 提交于 2019-11-27 03:02:24
问题 C# 6 brings compiler support for interpolated string literals with syntax: var person = new { Name = "Bob" }; string s = $"Hello, {person.Name}."; This is great for short strings, but if you want to produce a longer string must it be specified on a single line? With other kinds of strings you can: var multi1 = string.Format(@"Height: {0} Width: {1} Background: {2}", height, width, background); Or: var multi2 = string.Format( "Height: {1}{0}" + "Width: {2}{0}" + "Background: {3}", Environment

PHP variable interpolation vs concatenation [duplicate]

ε祈祈猫儿з 提交于 2019-11-27 01:23:02
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."!"; 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 just echo the string, no concatenation needed. 来源: https://stackoverflow.com/questions/16790501/php-variable

Use YAML with variables

谁说胖子不能爱 提交于 2019-11-27 00:12:09
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? benrugg 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 officially called "node anchors" when you set them and "references" when you use them later): Define