my code
import requests,json
name = ("hika")
content = requests.get(f"https://api.genderize.io/?name={name}").text
gender = json.loads(content)['gender']
print(f"Gender of {name} is {gender}")
I want to make it reads a txt file and tells me which names are males and which are females
CodePudding user response:
Here is a code reading names from path_to_txt_file.txt
file:
import requests,json
with open("path_to_txt_file.txt", "r") as f:
for line in f.readlines():
name = line.strip()
content = requests.get(f"https://api.genderize.io/?name={name}").text
gender = json.loads(content)['gender']
print(f"Gender of {name} is {gender}")
with open(f"{gender}.txt", "a") as fw:
fw.write(name "\n")