I'm doing a program in which using the list of dictionaries, I need to extract separately the values "tag", "attribute" and "Value". I have managed to get the values of "tag" and "value", but I am not able to extract the value "attribute" because it is a key of my dictionary.
I show you the list of dictionaries as printed on the screen:
[
["root-layout", { width: "248", height: "300", "background-color": "blue" }],
["region", { id: "a", top: "20", bottom: "", left: "64", right: "" }],
["region", { id: "b", top: "120", bottom: "", left: "20", right: "" }],
[
"region",
{ id: "text_area", top: "100", bottom: "", left: "20", right: "" }
],
[
"img",
{
src: "http://www.content-networking.com/smil/hello.jpg",
region: "a",
begin: "2s",
dur: "36s"
}
],
[
"img",
{
src: "http://www.content-networking.com/smil/earthrise.jpg",
region: "b",
begin: "12s",
dur: ""
}
],
[
"audio",
{
src: "http://www.content-networking.com/smil/hello.wav",
begin: "1s",
dur: ""
}
],
["textstream", { src: "http://gsyc.es/~grex/letra.rt", region: "text_area" }],
["audio", { src: "cancion.ogg", begin: "4s", dur: "" }]
];
import sys
from xml.sax import make_parser
from smallsmilhandler import SmallSMILHandler
if __name__ == "__main__":
try:
file = sys.argv[1]
parser = make_parser()
cHandler = SmallSMILHandler()
parser.setContentHandler(cHandler)
parser.parse(open(file))
listavalores = cHandler.get_tags()
for linea in listavalores:
lista_final = []
etiqueta = linea[0]
dic_atributo = linea [1].keys()
atributo = dic_atributo
valor = linea[1]['width']
print(etiqueta)
print(atributo)
print(valor)
except IndexError:
sys.exit("Usage:python3 karaoke.py file.smil")