我刚学python,这是我写的函数,数组的这些代码是我的构想,肯定是错的,所以想请python大神帮我修改一下,能够把这三个长度未知的参数存储在这个二维数组中,真的是非常感激不尽。。。
import xml.dom.minidom
import fileinput
import sys
import re
class Fileoperator:
def openfile(self,filepath):
dom = xml.dom.minidom.parse(filepath)
root = dom.getElementsByTagName('note')
a[][3]
for note in root:
durTick_index=note.getElementsByTagName("durTick")[0].firstChild.data
a[][1] = durTick_index
print a[][1]
noteNum_index = note.getElementsByTagName("noteNum")[0].firstChild.data
a[][2] = noteNum_index
print a[][2]
lyric_index=note.getElementsByTagName("lyric")[0].firstChild.data
for eachline in fileinput.input('F:\\final.txt'):
a=re.search(lyric_index,eachline)
if a:
a[][3] = fileinput.lineno()
print a[][3]
可我想要二维数组用来存储3个不同的参数,这样具体怎么实现呢
追答直接用list方式实现就可以了啊...
a=[]
a.appen(data)
list里面好像不能存储变量吧,并且我用你说的方法试了一下,还是不行,所以还是不懂怎么实现啊,能不能再具体一些呢,有劳了
追答把你现在出错的代码,贴出来我帮你看下吧。
追问数组的代码:save = [] save.append(durTick) save.append(noteNum) save.append(lyrick) print save 结果是:[480, 262.0, 171, 480, 294.0, 382...],但我想这样实现[480, 262.0, 171][ 480, 294.0, 382]...帮我再看一下,万分感谢啦
追答list1=[480, 262.0, 171]结果:
>>>
[[480, 262.0, 171], [480, 294.0, 382]]