raw_input 或输入未按新行完成
我正在使用Python语言对Cedrat Flux(一种有限元软件)进行编程。无论我尝试过什么Python命令都可以,但现在我尝试使用raw_input()
或input()
从命令行接收用户信息。不幸的是,尽管 Python 正常,但它不会通过按换行符或 Enter 键停止接收字符。 停止的唯一方法是关闭 Flux!
I am using Python language to program Cedrat Flux (a finite element software). Whatever Python commands I tried yet was O.K. But now I am trying to receive user information from command line using raw_input()
or input()
. Unfortunately despite normal Python it does not stop receiving characters by pressing New Line or Enter key.
The only way to stop is to close Flux!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
raw_input
(和input
,但这种区别在这里似乎不相关)只是从标准输入读取。您可以通过读取 sys.stdin 来手动执行此操作:如果这不起作用(即 sys.stdin.read(1) 也会阻塞,即使您输入了一些内容),标准输入可能是由主机应用程序重定向(在您的情况下为 Flux)。您可以使用主机应用程序的 API 附加到它或直接获取输入。
raw_input
(andinput
, but that distinction seems not relevant here) is just reading from stdin. You can do that manually by reading fromsys.stdin
:If that does not work (i.e. sys.stdin.read(1) blocks too, even when you input something), the standard input may have been redirected by the host application (Flux in your case). You may be able to use an API of the host application to attach to it or get the input directly.
您可以将所需的数据存储在文件中,然后调用
open(".../file").read()
来读取它。You can store the data you want in a file and call
open(".../file").read()
to read it.