AIX5.2 上的 python 非法指令
我像这样运行我的 python 脚本函数: 从文本文件中读取数据,并将数据存储为 dict。但在循环时,会出现非法指令。为什么会发生这种情况? 代码是这样的:
d={}
datafile=open('a.txt') # a big text file
for line in datafile:
line=line.rstrip('\n')
for token in line.split():
print("Parsing line %d." % token[0])
d[(int(token[0]))]=token[1:]
那么消息是这样的:
Parsing line 1.
Parsing line 2.
............
Parsing line 1064
Parsing line 1065
Illegal instruction
有什么问题吗?我的平台是 AIX 5.2 上的 python 2.6.2。 请帮助我,谢谢!
I run my python script functions like this:
read from a text file, and store the data as dict. But when in the loop, an Illegal instruction occurs. why this happens?
the code is like this:
d={}
datafile=open('a.txt') # a big text file
for line in datafile:
line=line.rstrip('\n')
for token in line.split():
print("Parsing line %d." % token[0])
d[(int(token[0]))]=token[1:]
then the message is like this:
Parsing line 1.
Parsing line 2.
............
Parsing line 1064
Parsing line 1065
Illegal instruction
what's the problem? my platform is python 2.6.2 on AIX 5.2.
please help me, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这看起来非常错误。
token
是line.split()
返回的字符串数组中的一个字符串。所以token[0]
是该字符串的第一个字符。因此,我不相信您会在输出中得到类似Parsing line 1065
的内容。正如 Mark 所写,您会看到一个TypeError
。请发布
不然没办法帮你。
This looks very wrong.
token
is a string in an array of strings returned byline.split()
. Sotoken[0]
is the first character of that string. Therefore I don't believe that you'll ever get anything likeParsing line 1065
in your output. As Mark wrote, you'd see aTypeError
.Please post
Otherwise there's no way to help you.