Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

is there a way to make the coad read a txt file and tell me what the each of the names gender is

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading