python中的列表、str和int帮助
我有这样的数字列表: 146168 174196 230252 258280 286308 314336 342364 370392 第一个数字代表我从代码中得到的值(起始数字),逗号后的第二个数字是结束值。我尝试使用start和end值来打印字符串。 以下是我的部分代码:python中的列表、str和int帮助,python,elementtree,Python,Elementtree,我有这样的数字列表: 146168 174196 230252 258280 286308 314336 342364 370392 第一个数字代表我从代码中得到的值(起始数字),逗号后的第二个数字是结束值。我尝试使用start和end值来打印字符串。 以下是我的部分代码: root = etree.parse(f) for lcn in root.xpath("/protein/match[@dbname='DB']/lcn"): start = lcn.get("start")
root = etree.parse(f)
for lcn in root.xpath("/protein/match[@dbname='DB']/lcn"):
start = lcn.get("start")
end = lcn.get("end")
print "%s, %s" % (start, end,)
if start <= end:
start = int(start+1)
print start
if start <= end:
print list(start)
start = int(start+1)
root=etree.parse(f)
对于root.xpath中的lcn(“/protein/match[@dbname='DB']/lcn”):
开始=lcn.get(“开始”)
end=lcn.get(“end”)
打印“%s,%s%”(开始、结束)
如果开始而不是
start = lcn.get("start")
end = lcn.get("end")
使用
这是因为lcn.get
返回一个字符串
使用start+=1
代替start=int(start+1)
。您不再需要转换为整数,start+=1
是start=start+1
的缩写
使用打印“%d,%d%”(开始,结束)
,而不是打印“%s,%s%”(开始,结束)
。结尾处的逗号是不必要的,start
和end
现在是整数,因此使用%d
而不是%s
更新:
而不是
while start <= end:
inRange = makeList.append[start]
start += 1
print inRange
如果使用Python3或
for i in xrange(start, end):
makeList.append(i)
print i
如果使用Python 2.而不是
start = lcn.get("start")
end = lcn.get("end")
使用
这是因为lcn.get
返回一个字符串
使用start+=1
代替start=int(start+1)
。您不再需要转换为整数,start+=1
是start=start+1
的缩写
使用打印“%d,%d%”(开始,结束)
,而不是打印“%s,%s%”(开始,结束)
。结尾处的逗号是不必要的,start
和end
现在是整数,因此使用%d
而不是%s
更新:
而不是
while start <= end:
inRange = makeList.append[start]
start += 1
print inRange
如果使用Python3或
for i in xrange(start, end):
makeList.append(i)
print i
如果使用Python 2。@ChadD,没有问题。一旦允许,请务必接受此答案。:)我就这么做了。再次感谢。所以我开始工作,但结果是每行一个字母,我这样做了。。启动@ChadD时,没有问题。一旦允许,请务必接受此答案。:)我就这么做了。再次感谢。所以我开始工作,但结果是每行一个字母,我这样做了。。开始时