0

I have problem with this script in LiClipse(Eclipse)

import stdio
import stddraw

# Read x and y scales from standard input, and configure standard
# draw accordingly. Then read points from standard input until
# end-of-file, and plot them on standard draw.

x0 = stdio.readFloat()
y0 = stdio.readFloat()
x1 = stdio.readFloat()
y1 = stdio.readFloat()

stddraw.setXscale(x0, x1)
stddraw.setYscale(y0, y1)

# Read and plot the points.
stddraw.setPenRadius(0.0)
while not stdio.isEmpty():
    x = stdio.readFloat()
    y = stdio.readFloat()
    stddraw.point(x, y)

stddraw.show()

I use this file as "Input file" in "Run configurations".

I get a black stddraw window which does not respond. If I type "Ctrl-Z" in LiClipse console, then I get a result sometimes.

I've run this script in debugger - it stops on line of stdio.py (with operator "line = sys.stdin.readline()") for last line of usa.txt.

I've run this file in Geany - it works!

Is it a bug in PyDeve (Eclipse)?

Thanks!

Andrew D
  • 113
  • 1
  • 1
  • 6

2 Answers2

0

The problem is that sys.stdin.readline() will keep waiting for an input... The stdin implementation on Eclipse won't give you an EOF until the program has actually finished (if you put prints after sys.stdin.readline(), you'll see that it'll print one last thing when you actually kill the program in Eclipse)... I'm not sure I'd consider this as a bug... maybe it could be a feature (i.e.: close stdin after reading input file) -- it's mostly an implementation detail that when you pipe something in the console it'll close stdin later on (and on Eclipse providing an input file will give you the input but will keep stdin open for the user to add more contents later on).

As a workaround my suggestion is putting an empty line and then checking if the line returned from sys.stdin.readline().strip() is empty -- and if it is, consider it reached EOF (or use some different marker for EOF) -- another alternative would be just reading it from a file, not from stdin.

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
0

I ran into the same problem. I am using sys.stdin.readlines(). I followed the directions in [https://stackoverflow.com/a/31287752/4586180][1] to configure eclipse to read a file my input file

I also checked the box to "create console if needed". After readlines() I was able to enter ^d in the console. This caused readlines() to complete

AEDWIP
  • 888
  • 2
  • 9
  • 22