我一直收到以下错误:
$ ./test.py
-bash: ./test.py: cannot execute binary file
Run Code Online (Sandbox Code Playgroud)
当试图通过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))
Run Code Online (Sandbox Code Playgroud)
我该如何解决??
在采取以下建议后,仍然得到相同的错误.
如果这有帮助,我试过了
$ python ./test.py
Run Code Online (Sandbox Code Playgroud)
得到了
$ python ./test.py …Run Code Online (Sandbox Code Playgroud) 正如先前(但不同)的问题所述,我正在尝试用Python找出一个"简单"的字典/数据库,它将从十个列表中检索一个名称,并提供所请求的信息.即输入可以是'John phone',其中输出是'John的电话号码是0401'(我已经拍了拍); 但我也可以输入'John Birthday'或'John hobbies',输出也会对应.
因为我是一个完整的菜鸟,我甚至不知道从哪里开始.几个小时的谷歌搜索和阅读讲义到目前为止没有任何结果.我觉得它与多重参数%函数有关,但我们的讲师真的不清楚如何进一步研究它.到目前为止,我所拥有的是:
#!/usr/bin/python
friends = {'John': {'phone' : '0401',
'birthday' : '31 July',
'address' : 'UK',
'interests' : ['a', 'b', 'c']},
'Harry': {'phone' : '0402',
'birthday' : '2 August',
'address' : 'Hungary',
'interests' : ['d', 'e', 'f']}}
name = raw_input ('Please enter search criteria: ')
if name in friends:
print "%s's phone number is: %s" % (name, friends[name]['phone'])
else:
print 'no data'
Run Code Online (Sandbox Code Playgroud)
我还想使用'while'功能,因此一旦获得该信息,prog就不会关闭,但不确定这是否合适.任何指针都会很棒,即使它是"尝试这种"的暗示,或指向相关网站的链接.
一个非常简单的while循环语句是什么,它会继续执行下面的程序,直到用户键入“exit”?
例如,
while response = (!'exit')
continue file
else
break
print ('Thank you, good bye!')
#I know this is completely wrong, but it's a try!
Run Code Online (Sandbox Code Playgroud)
到目前为止我的文件:
#!/usr/bin/python
friends = {'John' : {'phone' : '0401',
'birthday' : '31 July',
'address' : 'UK',
'interests' : ['a', 'b', 'c']},
'Harry' : {'phone' : '0402',
'birthday' : '2 August',
'address' : 'Hungary',
'interests' : ['d', 'e', 'f']}}
response = raw_input("Please enter search criteria, or type 'exit' to exit the program: ").split()
try: …Run Code Online (Sandbox Code Playgroud)