string-interpolation

psycopg2 difference between AsIs and sql module

拈花ヽ惹草 提交于 2019-12-01 12:59:50
To choose dynamically a table name in a query I used to use AsIs() from psycopg2.extensions ( http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.AsIs ), with the following syntax: cur.execute("SELECT * FROM %s WHERE id = %s;", (AsIs('table_name'), id)) However, the documentation now recommends to use the new psycopg2.sql module available in version 2.7 ( http://initd.org/psycopg/docs/sql.html#module-psycopg2.sql ) with the following syntax: from psycopg2 import sql cur.execute( sql.SQL("SELECT * FROM {} WHERE id = %s;") .format(sql.Identifier('table_name')), (id, ) What's the

How to Create Text Files from an Array of Values in Powershell

霸气de小男生 提交于 2019-12-01 11:41:29
I have a text file "list.txt" with a list of hundreds of URL's that I want to parse, along with some common-to-all config data, into individual xml files (config files) using each value in "list.txt", like so: list.txt contains: line_1 line_2 line_3 The boilerplate config data looks like (using line_1 as an example): <?xml version="1.0"?> <Website xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Url>line_1.mydomain.com</Url> <Title>line_1</Title> <Enabled>true</Enabled> <PluginInName>Tumblr</PluginInName> </Website> So if "list.txt" contains

psycopg2 difference between AsIs and sql module

拜拜、爱过 提交于 2019-12-01 10:31:18
问题 To choose dynamically a table name in a query I used to use AsIs() from psycopg2.extensions ( http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.AsIs ), with the following syntax: cur.execute("SELECT * FROM %s WHERE id = %s;", (AsIs('table_name'), id)) However, the documentation now recommends to use the new psycopg2.sql module available in version 2.7 ( http://initd.org/psycopg/docs/sql.html#module-psycopg2.sql ) with the following syntax: from psycopg2 import sql cur.execute(

Is it possible to pass interpolated strings as parameter to a method?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 04:02:50
I have started to use Interpolated Strings (new feature of C# 6) and it is really useful and gracefully. But according to my needs I have to pass format of string to a method as a parameter. Something like next: MyMethod(string format) In the past, I used it in the next way: MyMethod("AAA{0:00}") Now I tried this code: MyMethod($"AAA{i:00}") But this doesn't work, because i is created inside of the method and is out of scope in this context. Is it possible to use any trick for passing interpolated strings as a parameter to a method? You cannot do that, and that would not be a very good idea

Is it possible to pass interpolated strings as parameter to a method?

青春壹個敷衍的年華 提交于 2019-12-01 01:45:30
问题 I have started to use Interpolated Strings (new feature of C# 6) and it is really useful and gracefully. But according to my needs I have to pass format of string to a method as a parameter. Something like next: MyMethod(string format) In the past, I used it in the next way: MyMethod("AAA{0:00}") Now I tried this code: MyMethod($"AAA{i:00}") But this doesn't work, because i is created inside of the method and is out of scope in this context. Is it possible to use any trick for passing

What is the optional argument in C# interpolated string for?

≯℡__Kan透↙ 提交于 2019-11-30 17:01:58
Interpolated strings is one of the new features of C# 6.0. According to MSDN, the syntax of the embedded C# expressions can contain an optional, comma-separated value, deemed as <optional-comma-field-width> in the documentation . Unfortunately I didn't find what this field is for. From its name one might think that this value sets the maximal size of the "interpolated" field, but when I try the following expression: var p = Process.GetCurrentProcess(); Console.WriteLine($"Process name is {p.ProcessName, 5}"); I get the following output: Process name is LINQPad.UserQuery It's the minimum width

C# 6 how to format double using interpolated string?

不想你离开。 提交于 2019-11-30 05:34:06
I have used some new features of C# 6 incl. interpolated string for simple usage (showing message which contains string variables like $"{EmployeeName}, {Department}"). Now I want to use interpolated string for showing formatted double value. Example var aNumberAsString = aDoubleValue.ToString("0.####"); How can I write it as interpolated string? something like $"{aDoubleValue} ...." You can specify a format string after an expression with a colon ( : ): var aNumberAsString = $"{aDoubleValue:0.####}"; A colon after the variable specifies a format, Console.Write($"{aDoubleValue:0.####}"); 来源:

Parsing string interpolation in ANTLR

痴心易碎 提交于 2019-11-30 05:26:57
I'm working on a simple string manipulation DSL for internal purposes, and I would like the language to support string interpolation as it is used in Ruby. For example: name = "Bob" msg = "Hello ${name}!" print(msg) # prints "Hello Bob!" I'm attempting to implement my parser in ANTLRv3, but I'm pretty inexperienced with using ANTLR so I'm unsure how to implement this feature. So far, I've specified my string literals in the lexer, but in this case I'll obviously need to handle the interpolation content in the parser. My current string literal grammar looks like this: STRINGLITERAL : '"' (

Python string interpolation using dictionary and strings

社会主义新天地 提交于 2019-11-30 03:12:37
Given: dict = {"path": "/var/blah"} curr = "1.1" prev = "1.0" What's the best/shortest way to interpolate the string to generate the following: path: /var/blah curr: 1.1 prev: 1.0 I know this works: str = "path: %(path)s curr: %(curr)s prev: %(prev)s" % {"path": dict["path"],"curr": curr, "prev": prev} But I was hoping there is a shorter way, such as: str = "path: %(path)s curr: %s prev: %s" % (dict, curr, prev) My apologies if this seems like an overly pedantic question. Why not: mystr = "path: %s curr: %s prev: %s" % (mydict[path], curr, prev) BTW, I've changed a couple names you were using

String interpolation in Scala?

好久不见. 提交于 2019-11-30 01:05:40
问题 I wanted to ask if there is any type of string interpolation in Scala. I have made a search on the subject but 'till now I have found that there is no string interpolation. Is there plans to get implemented in next versions? Thanks! UPDATE String interpolation is going to be in scala 2.10 which you can try out since scala 2.10.RC1 is out (20/10/2012). You can check out this SIP for scala 2.11 which states that interpolated strings in the pattern matcher will be valid syntax. With the new