test-api / person.py
tqhoa's picture
Update person.py
b36ab5a
from importlib import resources
import random
class Person:
def __init__(self, age: int = 18, gender: int = 1, amount: int = 10) -> None:
self.age = age
self.gender = gender
self.amount = amount
def full_name(self):
results = []
first_name = self.read_file("first_name.txt")
if self.gender:
male_name = self.read_file("male.txt")
for i in range(self.amount):
full_name = "{} {}".format(random.choice(
first_name), random.choice(male_name))
results.append(full_name)
return results
female_name = self.read_file("female.txt")
for i in range(self.amount):
full_name = "{} {}".format(random.choice(
first_name), random.choice(female_name))
results.append(full_name)
return results
@staticmethod
def read_file(filename):
#with resources.open_text("", filename) as f:
with open(filename, 'r') as f:
data = f.read().splitlines()
return data