0

我在 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()

将此文件用作“运行配置”中的“输入文件”。

我得到一个没有响应的黑色 stddraw 窗口。如果我在 LiClipse 控制台中键入“Ctrl-Z”,有时我会得到结果。

我已经在调试器中运行了这个脚本 - 它在 usa.txt 的最后一行停止在 stdio.py 行(使用运算符“line = sys.stdin.readline()”)。

我已经在 Geany 中运行了这个文件——它有效!

它是 PyDeve (Eclipse) 中的错误吗?

谢谢!

4

2 回答 2

0

问题是它sys.stdin.readline()会一直等待输入...... Eclipse 上的标准输入实现在程序实际完成之前不会给你一个 EOF(如果你把 prints 放在后面sys.stdin.readline(),你会看到它会打印最后一件事当您实际在 Eclipse 中杀死程序时)...我不确定我是否会将其视为错误...也许它可能是一个功能(即:在读取输入文件后关闭标准输入)——它主要是一个实现详细说明,当您在控制台中通过管道传输某些内容时,它将稍后关闭标准输入(在 Eclipse 上提供输入文件将为您提供输入,但会保持标准输入打开,以便用户稍后添加更多内容)。

作为一种解决方法,我的建议是放置一个空行,然后检查从返回的行是否sys.stdin.readline().strip()为空——如果是,则认为它已达到 EOF(或为 EOF 使用一些不同的标记)——另一种选择是从一个文件,而不是来自标准输入。

于 2017-09-05T11:35:14.653 回答
0

我遇到了同样的问题。我正在使用 sys.stdin.readlines()。我按照 [ https://stackoverflow.com/a/31287752/4586180][1]中的说明配置 eclipse 以读取我的输入文件

我还选中了“如果需要创建控制台”框。在 readlines() 之后,我能够在控制台中输入 ^d 。这导致 readlines() 完成

于 2018-11-03T16:46:00.327 回答