derek73 / python-nameparser

A simple Python module for parsing human names into their individual components
http://nameparser.readthedocs.org/en/latest/
Other
653 stars 104 forks source link

Parts-based constructor #140

Closed jgarbers closed 1 year ago

jgarbers commented 1 year ago

It would be convenient to have a way to construct a HumanName from component parts rather than having it parse a string. If, for example, I get first, last, and middle names separately from a database, and want to use HumanName as a convenient way to pass those names around, the only way I've determined to do that is something like

hn = HumanName()
hn.first = db_record["First"]
hn.middle = db_record["Middle"]
hn.last = db_record["Last"]

A constructor that accepted individual name parts could make this cleaner:

hn = HumanName(first=db_record["First"], ...)

and also allow HumanNames to be constructed easily from a dict parsed from a JSON structure:

hn = HumanName(**name_dict)

When name parts are known, this would eliminate parsing overhead and avoid problems where, for example, a first name is "Jo Ann" and last name "Smith". In this case assembling the name into a string and parsing it would inappropriately assign "Ann" as a middle name.

Thank you for your consideration!