-1
Hello I have a for
that extracts data from an XML file and I wanted to iterate a count to show as for example like this:
1- O EAN é 7897748715180
2- O EAN é None
3- O EAN é 7897748729941
4- O EAN é 7897748729965
5- O EAN é 7897748729880
My code:
import xml.etree.ElementTree as ET
#Bibliotecas
#------------------------------------------------------------------------------------------
XML = input("Coloque o diretorio do XML: ").strip('"')
tree = ET.parse(XML)
root = tree.getroot()
print('\n')
ns = {'nfe': 'http://www.portalfiscal.inf.br/nfe'}
for det in root.findall('.//nfe:det', ns):
nItem = det.attrib['nItem']
EAN = det.find('.//nfe:cEAN', ns).text
Contagem = 1
print(f"{Contagem}- O EAN é {EAN}")
Contagem = Contagem + 1
I’m doing the Contagem +1
but it’s not adding up, how to add up?
The Count variable setting is inside the for, with each loop set to 1. Move the Count line = 1 to before starting the for, so it will be incremented at each loop
– Paulo C
It’s true @Pauloc I changed it and it worked
– user198451