faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 37 people (54%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

print "foo", without a space

Jul 5th, 2000 10:02
Nathan Wallace, Hans Nowak, Snippet 276, Tim Peters


"""
Packages: miscellaneous
"""
"""
> Is there another way of getting print to not make a newline than
> using:
>     print "foo",  ?
No.
> This because the comma always produces a space which necessary
> isn't that nice ...
That's a different issue than newlines.  In small doses, this devious
trick is quite pleasant:
"""
import sys
def no_space_before(x):
    sys.stdout.softspace = 0
    return x
ns = no_space_before
print 1, ns(2), 3, ns(4), 5
# 12 34 5
"""
the-great-thing-about-python-is-it's-so-obvious<wink>-ly y'rs  - tim
"""