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

时间:2011-01-17 09:21:25

标签: python py2app raw-input eoferror

我写了一个小脚本,帮助我解决拼字游戏和单词扭曲问题。当我从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

如何摆脱错误?

1 个答案:

答案 0 :(得分:2)

py2app打包为应用程序的Python程序没有可以输入输入的终端窗口。您需要提供一些更好的输入输入和提供输出的方法,例如使用Python的Tkinter模块。如果您的脚本从终端运行并且您想要创建可单击的应用程序,则将其打包为启动Automater会话的AppleScriptTerminal应用程序可能会更简单。