1,105,197 Community Members

Print on same line (w/o whitepace)

Member Avatar
shadwickman
Posting Pro in Training
495 posts since Jul 2007
Reputation Points: 159 [?]
Q&As Helped to Solve: 80 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello! I've run into a slight problem with my script.
As I iterate through a list of strings, I need to print each string, but they all need to print on the same line, so I used this:

for item in myList:
    print item,

The comma puts each item on the same line, but the problem is that it adds a space between the items. Is there any way around this? I cannot use:

out = ""
for item in myList:
    out += item
print out

Depending on the string, the colour in the console gets changed accordingly before printing it, therefore I cannot add them all to one output string and then that print last. Any help is appreciated!

Member Avatar
Aia
Nearly a Posting Maven
2,307 posts since Dec 2006
Reputation Points: 1,977 [?]
Q&As Helped to Solve: 236 [?]
Skill Endorsements: 20 [?]
 
0
 
Member Avatar
shadwickman
Posting Pro in Training
495 posts since Jul 2007
Reputation Points: 159 [?]
Q&As Helped to Solve: 80 [?]
Skill Endorsements: 0 [?]
 
0
 

Ah! sys.stdout.write() .... I've seen it before but I had no clue what it really was. Thanks for pointing it out, Aia!

Question Answered as of 5 Years Ago by Aia
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article