How do I create a multiline Python string with inline variables?

The common way is the format() function: >>> s = “This is an {example} with {vars}”.format(vars=”variables”, example=”example”) >>> s ‘This is an example with variables’ It works fine with a multi-line format string: >>> s=””‘\ … This is a {length} example. … Here is a {ordinal} line.\ … ”’.format(length=”multi-line”, ordinal=”second”) >>> print(s) This is a … Read more

Multiline TextView in Android?

If the text you’re putting in the TextView is short, it will not automatically expand to four lines. If you want the TextView to always have four lines regardless of the length of the text in it, set the android:lines attribute: <TextView android:id=”@+id/address1″ android:gravity=”left” android:layout_height=”fill_parent” android:layout_width=”wrap_content” android:maxLines=”4″ android:lines=”4″ android:text=”Lorem ipsum dolor sit amet, consectetur adipisicing … Read more

Best way to split string into lines

If it looks ugly, just remove the unnecessary ToCharArray call. If you want to split by either \n or \r, you’ve got two options: Use an array literal – but this will give you empty lines for Windows-style line endings \r\n: var result = text.Split(new [] { ‘\r’, ‘\n’ }); Use a regular expression, as indicated … Read more

What is the proper way to format a multi-line dict in Python?

I use #3. Same for long lists, tuples, etc. It doesn’t require adding any extra spaces beyond the indentations. As always, be consistent. mydict = { “key1”: 1, “key2”: 2, “key3”: 3, } mylist = [ (1, ‘hello’), (2, ‘world’), ] nested = { a: [ (1, ‘a’), (2, ‘b’), ], b: [ (3, ‘c’), … Read more

C multi-line macro: do/while(0) vs scope block [duplicate]

Andrey Tarasevich provides the following explanation: On Google Groups On bytes.com [Minor changes to formatting made. Parenthetical annotations added in square brackets []]. The whole idea of using ‘do/while’ version is to make a macro which will expand into a regular statement, not into a compound statement. This is done in order to make the … Read more

How to execute multi-line statements within Python’s own debugger (PDB)

You could do this while in pdb to launch a temporary interactive Python session with all the local variables available: (pdb) !import code; code.interact(local=vars()) Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. (InteractiveConsole) >>> When you’re done, use Ctrl-D to return to the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)