本文整理汇总了Python中person.Person方法的典型用法代码示例。如果您正苦于以下问题:Python person.Person方法的具体用法?Python person.Person怎么用?Python person.Person使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类person
的用法示例。
在下文中一共展示了person.Person方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_population
# 需要导入模块: import person [as 别名]
# 或者: from person import Person [as 别名]
def _create_population(self, initial_infected):
# TODO: Finish this method! This method should be called when the simulation
# begins, to create the population that will be used. This method should return
# an array filled with Person objects that matches the specifications of the
# simulation (correct number of people in the population, correct percentage of
# people vaccinated, correct number of initially infected people).
population = []
infected_count = 0
while len(population) != pop_size:
if infected_count != initial_infected:
# TODO: Create all the infected people first, and then worry about the rest.
# Don't forget to increment infected_count every time you create a
# new infected person!
pass
else:
# Now create all the rest of the people.
# Every time a new person will be created, generate a random number between
# 0 and 1. If this number is smaller than vacc_percentage, this person
# should be created as a vaccinated person. If not, the person should be
# created as an unvaccinated person.
pass
# TODO: After any Person object is created, whether sick or healthy,
# you will need to increment self.next_person_id by 1. Each Person object's
# ID has to be unique!
return population
示例2: _infect_newly_infected
# 需要导入模块: import person [as 别名]
# 或者: from person import Person [as 别名]
def _infect_newly_infected(self):
# TODO: Finish this method! This method should be called at the end of
# every time step. This method should iterate through the list stored in
# self.newly_infected, which should be filled with the IDs of every person
# created. Iterate though this list.
# For every person id in self.newly_infected:
# - Find the Person object in self.population that has this corresponding ID.
# - Set this Person's .infected attribute to True.
# NOTE: Once you have iterated through the entire list of self.newly_infected, remember
# to reset self.newly_infected back to an empty list!
示例3: updateRecord
# 需要导入模块: import person [as 别名]
# 或者: from person import Person [as 别名]
def updateRecord():
key=entries['key'].get()
if key in db:
record=db[key]
else:
from person import Person
record=Person(name='?',age='?')
for field in fieldnames:
setattr(record,field,eval(entries[field].get()))
db[key]=record
# if __name__=='__main__':
示例4: __init__
# 需要导入模块: import person [as 别名]
# 或者: from person import Person [as 别名]
def __init__(self, mother, doctor):
"""Initialize a Birth object."""
super(Birth, self).__init__(sim=mother.sim)
self.town = mother.town
self.biological_mother = mother
self.mother = mother
self.biological_father = mother.impregnated_by
self.father = self.mother.spouse if self.mother.spouse and self.mother.spouse.male else self.biological_father
self.subject = Person(sim=mother.sim, birth=self)
if self.father and self.father is not self.biological_father:
self.adoption = Adoption(subject=self.subject, adoptive_parents=(self.father,))
if self.biological_father is self.mother.spouse:
self.mother.marriage.children_produced.add(self.subject)
self.doctor = doctor
# Update the sim's listing of all people's birthdays
try:
mother.sim.birthdays[(self.month, self.day)].add(self.subject)
except KeyError:
mother.sim.birthdays[(self.month, self.day)] = {self.subject}
self._name_baby()
self._update_mother_attributes()
if self.mother.town:
self._take_baby_home()
if self.mother.occupation:
self._have_mother_potentially_exit_workforce()
if self.doctor: # There won't be a doctor if the birth happened outside the town
self.hospital = doctor.company
self.nurse = {
position for position in self.hospital.employees if
position.__class__.__name__ == 'Nurse'
}
self.doctor.baby_deliveries.add(self)
else:
self.hospital = None
self.nurses = set()
示例5: setUp
# 需要导入模块: import person [as 别名]
# 或者: from person import Person [as 别名]
def setUp(self):
# test data
self.first_name = "Marcus"
self.last_name = "Willock"
self.birthday = date(1988, 1, 19)
self.gender = "male"
self.likes = ["Python", "Golang"]
self.dislikes = ["Waking up early", "reality tv"]
# creating a Marcus clones!
self.person = Person(self.first_name,
self.last_name,
self.birthday,
self.gender,
self.likes,
self.dislikes)
self.relationship1 = "alter_ego"
self.relationship2 = "hater"
self.gender1 = "male"
self.gender2 = "female"
self.add_greeting1 = (self.relationship1, self.gender1, self.say_hi)
self.add_greeting2 = (self.relationship1, self.gender2, self.say_hi)
self.add_greeting3 = (self.relationship2, self.gender1, self.say_hi)
self.add_greetings = [self.add_greeting1,
self.add_greeting2,
self.add_greeting3]
self.greetings = Greetings(self.default_greeting)