string-interpolation

Is it possible to temporarily disable Python's string interpolation?

空扰寡人 提交于 2019-12-05 00:25:44
I have a python logger set up, using python's logging module. I want to store the string I'm using with the logging Formatter object in a configuration file using the ConfigParser module. The format string is stored in a dictionary of settings in a separate file that handles the reading and writing of the config file. The problem I have is that python still tries to format the file and falls over when it reads all the logging-module-specific formatting flags. { "log_level":logging.debug, "log_name":"C:\\Temp\\logfile.log", "format_string": "%(asctime)s %(levelname)s: %(module)s, line %(lineno

String interpolation issues

ε祈祈猫儿з 提交于 2019-12-04 14:59:56
问题 I'm trying to figure out why my unit test fails (The third assert below): var date = new DateTime(2017, 1, 1, 1, 0, 0); var formatted = "{countdown|" + date.ToString("o") + "}"; //Works Assert.AreEqual(date.ToString("o"), $"{date:o}"); //Works Assert.AreEqual(formatted, $"{{countdown|{date.ToString("o")}}}"); //This one fails Assert.AreEqual(formatted, $"{{countdown|{date:o}}}"); AFAIK, this should work correctly, but it appears that it doesn't pass the formatting parameter in correctly, it

What's the difference between raw string interpolation and triple quotes in scala

点点圈 提交于 2019-12-04 07:48:09
问题 Scala has triple quoted strings """String\nString""" to use special characters in the string without escaping. Scala 2.10 also added raw"String\nString" for the same purpose. Is there any difference in how raw"" and """""" work? Can they produce different output for the same string? 回答1: Looking at the source for the default interpolators (found here: https://github.com/scala/scala/blob/2.11.x/src/library/scala/StringContext.scala) it looks like the "raw" interpolator calls the identity

PHP $_Server Not Working Properly [duplicate]

允我心安 提交于 2019-12-04 05:35:51
问题 This question already has answers here : What is the difference between single-quoted and double-quoted strings in PHP? (10 answers) Closed 5 years ago . I have the following line: <div class='social'>http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]</div> It's all great and it displays the current link, let's say: http://www.example.com/mypage.php Now I want to associate this with a variable as such $myURL = 'http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]' When I echo this out I get "http://$

Ignore str.format(**foo) if key doesn't exist in foo

旧街凉风 提交于 2019-12-04 04:42:26
问题 I am trying to get an email template together. The message content will be dependent on values within a dictionary. However, the dictionary might not contain all the keys each time. This currently is fine as all values are in the dictionary ( 'Title' , 'Surname' , 'Additional Details' ): practise_dict = {"Additional Details":"blah blah blah blah", "Title": "Mr", "Surname": "Smith", "URL": "/test/tester"} msg = """From: John Smith <no-reply@somethingsomething.co.uk> To: {Title} {Surname} <blah

How can I do string interpolation in JavaScript?

大憨熊 提交于 2019-12-04 03:40:55
问题 Consider this code: var age = 3; console.log("I'm " + age + " years old!"); Are there any other ways to insert the value of a variable in to a string, apart from string concatenation? 回答1: Since ES6, you can use template literals: const age = 3 console.log(`I'm ${age} years old!`) P.S. Note the use of backticks: `` . 回答2: tl;dr Use ECMAScript 2015's Template String Literals, if applicable. Explanation There is no direct way to do it, as per ECMAScript 5 specifications, but ECMAScript 6 has

How to replace string in angular 2?

我的未来我决定 提交于 2019-12-04 03:07:31
I have used with below interpolation in html page. <div>{{config.CompanyAddress.replace('\n','<br />')}}</div> and also used <div>{{config.CompanyAddress.toString().replace('\n','<br />')}}</div> But both are showing text as below {{config.CompanyAddress.replace('\n','<br />')}} {{config.CompanyAddress.toString().replace('\n','<br />')}} Siddharth Sharma You can use a pipe for the same: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'replaceLineBreaks'}) export class ReplaceLineBreaks implements PipeTransform { transform(value: string): string { return value.replace(/\n/g, '

Overloaded string methods with string interpolation

六月ゝ 毕业季﹏ 提交于 2019-12-04 01:43:18
Why does string interpolation prefer overload of method with string instead of IFormattable ? Imagine following: static class Log { static void Debug(string message); static void Debug(IFormattable message); static bool IsDebugEnabled { get; } } I have objects with very expensive ToString() . Previously, I did following: if (Log.IsDebugEnabled) Log.Debug(string.Format("Message {0}", expensiveObject)); Now, I wanted to have the IsDebugEnabled logic inside Debug(IFormattable) , and call ToString() on objects in message only when necessary. Log.Debug($"Message {expensiveObject}"); This, however,

Scala String interpolation with Format, how to change locale?

半腔热情 提交于 2019-12-04 00:56:41
When doing format string interpolation in Sweden I get a comma instead of a dot when creating strings with decimal numbers: scala> val a = 5.010 a: Double = 5.01 scala> val a = 5.0101 a: Double = 5.0101 scala> f"$a%.2f" res0: String = 5,01 My question is, how do I set the format so that I get the result 5.01 ? I would like to be able to set the locale only for that String, i.e. so that I don't change the locale for the whole environment. Cheers, Johan VonC Using the same Java library number formatting support accessible from StringOps enriched String class , you could specify another locale

ruby here documents

情到浓时终转凉″ 提交于 2019-12-03 22:15:35
I am trying to write a method in Ruby that uses a here-document of HTML code with input variables and fills them in accordingly. My method is: calcForm(left, op, right, result) The html tags I am using are <input type="text" name="left" value="?????"> <select name="op"> <option value="add" ?????>+</option> <option value="mul" ?????>*</option> </select> <input type="text" name="right" value="?????"> = ????? Everywhere there are question marks my method has to fill in with variables left, op, right, and result. For example, calcForm(6, "mul", 7, 42) should return the string: <input type="text"