February 27th, 2006, 12:59 AM
Don't need gap between char and digit
I am printing some characters in a line and their positions using this statement:
and a typical output is;
However the output that I prefer is this;
How can I get rid of the gap inbetween?
Thanks for your help.
February 27th, 2006, 01:42 AM
use a formatted string:
For more info have a look at:
Python String Formatting
Because %s can be used to convert an object to a string
is also valid.
Last edited by Grim Archon; February 27th, 2006 at 01:45 AM.
February 27th, 2006, 03:49 AM
Thanks alot, that does the job!
February 27th, 2006, 11:56 AM
Alternatively, if you're used to other programming languages, you can:
Unfortunately, this method doesn't automatically convert whatever into strings, so you can't print out an integer without explicitly converting before-hand.
sys.stdout is a file-like object, which you can write to, but if you want a newline, you explicitely add a "\n" to it. Also, as far as I know, print makes a call to sys.stdout.write(whateverYouWannaPrint + "\n")
P.S. Just noticed, the first sys on the highlighted code isn't red.