使用 py2app 创建应用程序后,Python raw_input 导致 EOFError

发布于 2024-10-12 19:09:45 字数 2104 浏览 2 评论 0原文

我编写了一个小脚本来帮助我解决拼字游戏和文字扭曲问题。当我从 Mac OS X 终端运行它时,它工作正常。我想将脚本作为独立的 Mac 应用程序与我的朋友分享。因此我使用 py2app 来实现此目的,但是当我双击它时应用程序崩溃了。控制台显示以下错误消息:

1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875] Enter letters: Traceback (most recent call last):
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]   File "/Users/***/wordwarp/dist/warp.app/Contents/Resources/__boot__.py", line 137, in <module>
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]     _run('warp.py')
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]   File "/Users/***/wordwarp/dist/warp.app/Contents/Resources/__boot__.py", line 134, in _run
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]     execfile(path, globals(), globals())
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]   File "/Users/***/wordwarp/dist/warp.app/Contents/Resources/warp.py", line 4, in <module>
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]     word = raw_input("Enter letters: ")
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875] EOFError: EOF when reading a line
1/17/11 2:13:51 PM warp[9875] warp Error
1/17/11 2:13:51 PM warp[9875] warp Error
1/17/11 2:13:52 PM com.apple.launchd.peruser.501[469] ([0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]) Exited with exit code: 255

这是实际的脚本:

import string

word = raw_input("Enter letters: ")
dict = open('dict.txt')
wordmap = {}
for c in string.lowercase:
    wordmap[c] = 0

for c in word:
    if c in wordmap:
        wordmap[c] = wordmap[c]+1

for line in dict:
    line = line.strip()
    if len(line) >= 3:
        linemap = {}
        for c in string.lowercase:
            linemap[c] = 0
        for c in line:
            if c in linemap:
                linemap[c] = linemap[c]+1
        match = True
        for c in linemap:
            if linemap[c] > wordmap[c]:
                match = False
        if match is True:
            print line

如何消除该错误?

I have written a small script that helps me solve scrabble and word-warp problems. It works fine when I run it from Mac OS X terminal. I would like to share the script with my friends as a standalone Mac app. Hence I used py2app for this, but the App crashed when I double-click on it. The console shows the following error message:

1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875] Enter letters: Traceback (most recent call last):
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]   File "/Users/***/wordwarp/dist/warp.app/Contents/Resources/__boot__.py", line 137, in <module>
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]     _run('warp.py')
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]   File "/Users/***/wordwarp/dist/warp.app/Contents/Resources/__boot__.py", line 134, in _run
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]     execfile(path, globals(), globals())
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]   File "/Users/***/wordwarp/dist/warp.app/Contents/Resources/warp.py", line 4, in <module>
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]     word = raw_input("Enter letters: ")
1/17/11 2:13:51 PM [0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875] EOFError: EOF when reading a line
1/17/11 2:13:51 PM warp[9875] warp Error
1/17/11 2:13:51 PM warp[9875] warp Error
1/17/11 2:13:52 PM com.apple.launchd.peruser.501[469] ([0x0-0x4a44a4].org.pythonmac.unspecified.warp[9875]) Exited with exit code: 255

Here is the actual script:

import string

word = raw_input("Enter letters: ")
dict = open('dict.txt')
wordmap = {}
for c in string.lowercase:
    wordmap[c] = 0

for c in word:
    if c in wordmap:
        wordmap[c] = wordmap[c]+1

for line in dict:
    line = line.strip()
    if len(line) >= 3:
        linemap = {}
        for c in string.lowercase:
            linemap[c] = 0
        for c in line:
            if c in linemap:
                linemap[c] = linemap[c]+1
        match = True
        for c in linemap:
            if linemap[c] > wordmap[c]:
                match = False
        if match is True:
            print line

How can I get rid of the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姜生凉生 2024-10-19 19:09:45

py2app 包装为应用程序的 Python 程序没有用于输入输入的终端窗口。您需要提供一些更奇特的输入和提供输出的方式,例如使用 Python 的 Tkinter 模块。如果您的脚本从终端运行并且您想要创建一个可点击的应用程序,那么将其打包为启动 AutomaterAppleScript 应用程序可能会更简单终端会话。

Python programs wrapped as apps by py2app do not have a terminal window from which to enter input. You would need to supply some fancier way of enter input and suppling output, for example by using Python's Tkinter module. If your script runs from the terminal and you want to make a clickable application, it would likely be simpler to package it as an Automater or AppleScript application that launches a Terminal session.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文