0
Hello I have a program to check if there is a string inside a file like this:
import xml.etree.ElementTree as ET
#Bibliotecas
#------------------------------------------------------------------------------------------
text = input("Coloque o diretorio do fisico: ").strip('"')
arquivo = open(text,"r", encoding="utf8")
for linha in arquivo:
lista = linha
#localiza arquivo,lista todos os itens
#------------------------------------------------------------------------------------------
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']
quantidade = det.find('.//nfe:qCom', ns).text.strip('000').strip('.')
EAN = det.find('.//nfe:cEAN', ns).text
#importa XML, obtem os campos EAN,quatidade
#------------------------------------------------------------------------------------------
if lista is None:
if lista in EAN:
print(EAN)
print("EAN encontrado!")
#print("#------------------------------#")
else:
print(lista)
print("EAN nao encontrado!")
#print("#------------------------------#")
else:
print(lista)
print("EAN nao encontrado!")
#print("#------------------------------#")
#obtem o campo EAN e verifica se foi encontrado ou nao.
But the problem is that no matter if the data are equal, the code still responds that it does not find and I do not know why.
THE XML:
<nfeProc xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe Id="NFe35200811625533000185550010000043291000219014" versao="4.00">
<ide>
...
</ide>
<emit>
...
</emit>
<dest>
...
</dest>
<det nItem="1">
<prod>
<cProd>ET-CAM 01</cProd>
<cEAN/>
<xProd>CAMERA ESTAC MISTA (FURADA + SUP. BORBOLETA)</xProd>
<NCM>85258029</NCM>
<CEST>2106300</CEST>
<CFOP>5405</CFOP>
<uCom>UNI</uCom>
<qCom>20.0000</qCom>
<vUnCom>22.0000</vUnCom>
<vProd>440.00</vProd>
<cEANTrib/>
<uTrib>UNI</uTrib>
<qTrib>20.0000</qTrib>
<vUnTrib>22.0000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
...
</imposto>
</det>
<det nItem="2">
<prod>
<cProd>ET-CAM 02</cProd>
<cEAN>7898622140258</cEAN>
<xProd>CAMERA ESTAC DIANTEIRA</xProd>
<NCM>85258029</NCM>
<CEST>2106300</CEST>
<CFOP>5405</CFOP>
<uCom>UNI</uCom>
<qCom>10.0000</qCom>
<vUnCom>26.9000</vUnCom>
<vProd>269.00</vProd>
<cEANTrib>7898622140258</cEANTrib>
<uTrib>UNI</uTrib>
<qTrib>10.0000</qTrib>
<vUnTrib>26.9000</vUnTrib>
<indTot>1</indTot>
</prod>
The TXT file:
None
7898622140258
If anyone can help me I’d appreciate it please
What is the content of the first file (the one pointed out by
text
)? The idea is to see which words of this file appear in XML?– hkotsubo
updated with txt, yes that’s the idea
– user198451
That one
None
in the file means that if the EAN is empty it must also be found?– hkotsubo
That one
none
can come from xml so I made aif
to check if it isnone
if she is not wanted– user198451
If
EAN
forNone
means the tag is empty so you wouldn’t even need to have it in the first file– hkotsubo