'writing to an excel file only when certain conditions are fulfilled.. python program

person = Person()

#Fetching a person and then writing it to an excel file #Need to write only if certain conditions are fulfilled

def fetchdata(idnumber):
    m = person.details(idnumber)
    name = m.name
    id =m.id
    known_for_department = m. known_for_department
    gender = m.gender
    if gender == 1:
        gender= "Female"
    elif gender== 2:
        gender= "Male"
    else:
        gender = "Not specified"
    place_of_birth = m.place_of_birth
    dob = m.birthday
    also_known_as = m.also_known_as
    print(f"{id} - {name} - {gender} ")
    data = [name, id, known_for_department, gender, place_of_birth, dob]
    for value in also_known_as:
        data.append(value)
    return data
    


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source