print "foo", without a space

Arad Rostampour arad at fc.hp.com
Fri Nov 12 06:46:56 CET 1999


Nothing with print comes to mind off hand, but you could just use
sys.stdout.write() instead (it wont insert a space).

Enjoy,
Arad
--
Arad Rostampour- arad at fc.hp.com
NT Platform and I/O Team
Software and System Development Lab
Hewlett-Packard

Mikael Johansson wrote in message <382AD3BB.69899CBD at helsinki.xx>...
>
>Hello All!
>
>Is there another way of getting print to not make a newline than
>using:
>    print "foo",  ?
>This because the comma always produces a space which necessary
>isn't that nice, for example:
>
>for i in range (1,30):
>    print i,
>    if i%10==1 and i<>11: print "st",
>    elif i%10==2 and i<>12: print "nd",
>    elif i%10==3 and i<>13: print "rd",
>    else: print "th",
>    print "fish"
>
>Now you would like the "endings" to come right after the number.
>There is naturally always some way to get around this, in this
>case for example:
>
>end=["st","nd","rd","th"]
>for i in range(1,30):
>    print `i`+end[max(min(abs(i)%10,4)-1-
>    4*(not(int('0'+`abs(i)`[-2:-1])-1)),-1)],'fish'
>
>OK, this got a bit out of hand, the above looks terrible, does
>anyone see how it could be simplified? At least it's more general
>than the above as it can handle the whole range of integers,
>including negative ones :-) However it shows that it would be
>less obfuscating to have a print statement that could continue
>printing on the same line without a space.
>
>If there isn't an easy way for this, I suggest the following:
>    print "foo".
>So that a dot at the end of the line would mean "no space either".
>
>Appreciating any comments.
>
>Have a nice day,
>    Mikael J.
>    for e-mail note that the country code for Finland is not xx






More information about the Python-list mailing list