I have been using the function sys.stdout.write(string)
but I was wondering if there is another method for this purpose. Thanks in advance!
Asked
Active
Viewed 292 times
3

Frandman
- 43
- 3
-
Which version of Python are you using? – rlms Dec 04 '13 at 16:19
-
Oh sorry, i forget, python 2.7 – Frandman Dec 04 '13 at 16:20
-
Maybe is better to say "without control characters"... @sweeneyrod – Frandman Dec 04 '13 at 16:40
-
Maybe, that seemed less clear to me, as in Python 2.x the only things printed after a `print` statement are newlines and spaces, but I won't change it back. – rlms Dec 04 '13 at 16:41
1 Answers
11
Python 3.x:
print(string, end="")
Python 2.x:
from __future__ import print_function
print(string, end="")
or
print string, # This way adds a space at the end.
From the second answer of the duplicate question, I got this idea:
Instead of something like this:
>>> for i in xrange(10):
print i,
1 2 3 4 5 6 7 8 9 10
you might be able to do this:
>>> numbers = []
>>> for i in xrange(10):
numbers.append(i)
>>> print "".join(map(str, numbers))
12345678910
I would recommend import
ing print_function
. Or (tongue-in-cheek answer) upgrading to Python 3.x!

rlms
- 10,650
- 8
- 44
- 61
-
Thank you, the problem with this is that i also don't want an extra space, i'll edit my question ;) – Frandman Dec 04 '13 at 16:18