我是个业余程序员。每次我运行脚本时
invalid literal for int() with base 10
来了。你知道吗
该代码用于将dumchar\u信息文件散点.txt. 你知道吗
代码来自this site
import sys
import string
import re
ins = open( "dumchar.txt", "rb" )
outs = open( "scatter.txt", "wb" )
for line in ins:
linesp = re.split('\W+', line)
name = linesp[0].upper()
start = int(linesp[2],16)
block = linesp[5]
if block != 'misc':
start = start + 0x600000
outs.write(name + " " + string.replace(hex(start), "L", "") + "\n{\n}\n")
ins.close()
outs.close()
问题出在文件中,因为它以您期望的格式开始,但是当您继续读取它时,格式在最后5行中发生了变化。我说的是:
这正是它的变化,从有数字,你要找的只是描述(部分)_名称:分区名称。。。). 您可以更改文件以删除最后5行,也可以更改脚本,使其在不再具有有效输入时停止读取文件。你知道吗
你还需要删掉标题的第一行,因为这也会弄乱格式。所以这条线
看到了吗丹尼斯。弗里德曼的答案。你知道吗
问题是linesp[2]的格式并不总是您所期望的格式。正如Kamal Sadek正确指出的,问题在于文件的第一行和最后五行,其中linesp[2]不是十六进制数。你知道吗
解决这个问题的方法是增加
就在之前
相关问题 更多 >
编程相关推荐