我一直收到以下错误:
$ ./test.py
-bash: ./test.py: cannot execute binary file
尝试通过cygwin在python中运行以下文件时:
#!usr/bin/python
with open("input.txt") as inf:
try:
while True:
latin = inf.next().strip()
gloss = inf.next().strip()
trans = inf.next().strip()
process(latin, gloss, trans)
inf.next() # skip blank line
except StopIteration:
# reached end of file
pass
from itertools import chain
def chunk(s):
"""Split a string on whitespace or hyphens"""
return chain(*(c.split("-") for c in s.split()))
def process(latin, gloss, trans):
chunks = zip(chunk(latin), chunk(gloss))
我该如何解决这个问题?
接受以下建议后,仍然会出现同样的错误。
如果这有帮助,我试过
$ python ./test.py
得到了
$ python ./test.py
File "./test.py", line 1
SyntaxError: Non-ASCII character '\xff' in file ./test.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
答案 0 :(得分:2)
有一个问题。你错过了#!usr/bin/python
中usr前面的'/'。你的行应该是这样的。
#!/usr/bin/python
答案 1 :(得分:1)
除了保护文件可执行文件外,#!/usr/bin/python
可能无效。至少它在Red Hat或Ubuntu Linux上从未为我工作过。相反,我把它放在我的Python文件中:
#!/usr/bin/env python
我不知道这在Windows平台上是如何工作的。