0

After reading the intresting articles of vegaseat, I finally decided to get my toes wet.
So I installed Pyton 3.3.2 amd the plugin for Visual Studio 2010.
The best learning is of course practice, so I started coding right away.
Here is my first try:

import sys
print('Hello World')
print('I like internet for:')
for item in ['email', 'surfing', 'home']:
    print(item)
print
c=sys.stdin.read(1)

This works,but if I want to eliminate the newline, auto added by the print function, nothing is printed.
Google proposed, end, sep and comma, but nothing seems to work.
Anyone any ideas?
Thanks in advance for a solution.

4
Contributors
8
Replies
40
Views
3 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • for item in ['email', 'surfing', 'home']: print(item, end='', flush= True) or: for item in ['email', 'surfing', 'home']: print(item, end='') print() I found someone who came up with a good argument why it is that way: [klick me](http://www.gossamer-threads.com/lists/python/python/705025#705025) Read More

  • 1

    Starting with Python3 the print statement has been replaced with a much more useful print() function. There is still a lot of Python2 code around, so be aware. Enjoy Python! Read More

-2

How about using sys.stdout.write(item)

IIRC using print should be this: print(item, end="")

Edited by pritaeas

0

Thans for the answer pritaeas.
I already tried both options, but for some reason nothing is printed.

0

I found out.
It appears you have to flush the output stream print(item,end=" ",flush=True) What could be a reason to do it this way?

2
for item in ['email', 'surfing', 'home']: 
    print(item, end='', flush= True)

or:

for item in ['email', 'surfing', 'home']: 
    print(item, end='')
print()

I found someone who came up with a good argument why it is that way:
klick me

Edited by Dimitri_1

Comments
excellent!
Exellent Click me!
0

Could be your IDE acting up.
Also your line 6 needs to be print()

No need to putz around with sys

Edited by vegaseat

0

@vegaseat: Could be I'm still an absolute beginner in Python, but I'm learning.
This is what I think my problem was:
When I tried to put all tree strings on one line, I used a print function and suppressed the newline. But I closed of with a print statement (see line 6) Which I guess does nothing, not even print a newline. When I use a print function print() it works! Correct me if I'm wrong.

Edited by ddanbe: addition

1

Starting with Python3 the print statement has been replaced with a much more useful print() function. There is still a lot of Python2 code around, so be aware. Enjoy Python!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.