String Formatting
The section of the manual on String Formatting Operations is hidden in the section on Sequence types.
Tutorial on the new string formatting method format() in Python 3.0: Py3kStringFormatting
Direct Variable Reference
A common trick you can use when writing strings is to refer directly to variables.
If you want to refer to global variables, you can replace vars() with globals().
Printing Percentages
Print strings without newlines and spaces
You may find it tricky to print out a feed of numbers (as output from within a loop) on one line, without being separated by a space. An example could be output such as
Processing... [1][2][3][4][5][6] Completed.
The standard print statement automatically inserts newlines. This can be overcome with
but a space will get inserted between successive prints. One way to get around this is using sys.stdout:
which will work properly.
See Also
Discussion
You can also print a backspace ('\b') to swallow the extra space. eg:
Unfortunately, this produces a mess if output is being directed to a file; it's best to avoid printing the space if you don't want it.
Variable name substitution using format and eval
I want to print out all member of sys, then what I need is