1
I would like to know how to check a TXT file and if you have a line like it does not add the content again, otherwise it adds. I tried to do so:
Tokens is an array with several strings, for example:
['Nzc3NzA2MTc2MzA4NzA3Mzc5.X7HVkg.v85rDccvWP-HJJxD_SMonOu', 'Nzc3NzA3ODI2Njg0MjMxNzEy.X7HXBw.CvxmjqeS8sW9Rx1sEy2ESLZ']
I would like to check this array, and on each item in the list it checks if it already has this token in the notepad, and if it doesn’t have it adds, if it already has it, you don’t need to do anything but print that it already exists:
for i in range(0, len(tokens)):
print(str(tokens[i]))
with open('tokens.txt', "rt") as f:
datafile = f.readlines()
for line in datafile:
if str(tokens[i]) in line:
print("Já possue esse token")
else:
with open('tokens.txt', "w") as f:
f.write(str(tokens[i]) + '\n')
message = str(tokens[i])
However it is not working, the variable "message" always receives the token that was already written in . TXT, what should I do?
What is this variable
tokens
? You can edit your question by adding this information?– Rfroes87
It is to check each string of the array in each row, and if the string is not present in any line of the . txt, the string must be written at the end of the right file?
– Henrique Hott