Reputation: 9
i need to save output result to text file but can't able to save can anyone please help me to solve this problem
def list_checker():
list_file = input("List of numbers: ")
usr = input("Username Target: ")
list = open(list_file, 'r').read().splitlines()
for num in list:
try:
ress = check(num, usr)
if ress == '__err__':
print ("Null")
elif ress.lower() == usr.lower():
f = open("hit.txt", "a")
f.write(ress+":"+num)
f.close()
print ("Number: {} <{}>".format(num, "OK:)"))
break
else:
print ("Number: {} <{}>".format(num, "OK:)"))
except:
print ("Number: {} <{}>".format(num, "OK:)"))
and this is output result
Null
Number: 919998802233 <OK:)>
Null
Number: 919722568652 <OK:)>
Null
Null
Null
Number: 917623004040 <OK:)>
Null
Null
Null
how to save this output only showed number in result
Upvotes: 1
Views: 80
Reputation: 1542
This should work hopefully ;)
def list_checker():
list_file = input("List of numbers: ")
usr = input("Username Target: ")
list = open(list_file, 'r').read().splitlines()
for num in list:
try:
ress = check(num, usr)
if ress == '__err__':
print ("Null")
elif ress.lower() == usr.lower():
with open("hit.txt", "a") as writer:
writer.writelines(f'{ress}:{num}\n')
print ("Number: {} <{}>".format(num, "OK:)"))
break
else:
print ("Number: {} <{}>".format(num, "OK:)"))
except:
print ("Number: {} <{}>".format(num, "OK:)"))
Upvotes: 1