0
Hello.
I’m having trouble checking null value in list I have a json, whose section that gives me trouble is below:
{
"id": "200827",
"nome": "Emporio",
"idPai": null,
"nomePai": null
},
I understood that if you make the following command:
if lista[linha][coluna]:
the following code is only executed if the value is not null, but that is not what happens to me. I’m trying to run this snippet of code that doesn’t answer like this.
You should only enter the block if the value of the first column is not null. In this case, I test the value of the third column and only interested in cases of null value, however the if clause never returns false, although in the fifth iteration it should fall in Else, with the print list at the end.
if original[i][0]:
if original[i][2]:
print (original[i][2])
else:
executa tudo o que me interessa
Jamais entra nesta parte do código
Output from Print:
['200828']
['200827']
['200769']
['200769']
[None]
I’m afraid you’re making some very basic mistake, but I’m not quite sure what it would be.
Alano, can you leave the rest of the code in question ? I don’t think it is possible to answer it only with what you have put.
– JeanExtreme002
it was possible to answer yes, but only because it has the printed output of that print there. Otherwise I would have to have the code that reads the json, and a real example of how is this json there.
– jsbueno
but yes, what is happening, s and the JSON is this right there, is that it is being read wrong into Python. Using a number to access the value instead of the keys
"id", "nome", ...
suggests that the data is not being imported into Python in the correct way.– jsbueno
jsbueno already solved the problem. As for the use of indexes instead of key names, I wanted to make the code more generic. But I’ve rethought.
– Alano