So my plan here is simple, I want to store some information in a JSON file and, later in the code, I plan to look in the JSON file for one random piece among all information I stored previously and, after that, delete the specific one I used.
I've been using the following code for randomizing the piece of information I'm getting and trying to delete it from the JSON file:
sucesso = None
while sucesso is None:
try:
procurador = random.randint(1,10)
idselecionado = datapass[procurador]
sucesso = 1
except:
print("ainda procurando...")
pass
del datapass[procurador]
And the JSON file is very basic, like this:
["1fFTHMtvoZHIcJQBK75MS22aM-UL5ucKx", "1PtINIlElccwKuN26gqdJmhA1CtctFO--",
"1sT_AjnNTtRCWsIkzC9SJc1L9XvwTqV7u", "19wnN_RoCQZZ5ykRy6DLxq6YNTkIwZV5s"]
A couple of things that are important on this:
- The first one on the JSON file is not supposed to be taken, ever.
- Normally, there will be more than ten id's on the JSON file, but I don't think there will be a problem with that since the while will rerun if the random one is not ok
- The code goes into the first part (the
try
) but it doesn't go all the way to the end, basically stops at the randint, and then it prints "ainda procurando..." from the except and finally closes without running properly.