Reference¶
- class address.Book(path=None)¶
Implementation of an address book.
- add_entry(entry)¶
Add an entry to the book
Parameters: entry (Entry) – An object of Entry class, representing an entry in an address book
- add_field(field)¶
- delete_entry(index)¶
Delete an entry from the book
Parameters: index (Int) – The index of the entry to be deleted
- edit_entry(index, attr, value)¶
Edit an existing entry in the book
Parameters: - index (Int) – The index of the entry to be edited
- attr (String) – The attribute of the entry to be edited
- value (String) – The new value for the target attribute
- export_to(indexes, path)¶
Export address to a tsv file
Parameters: - path (String) – Path of the destination file.
- indexes (List of Int) – Indexes of the entries to be exported
- get_entry(index)¶
Return an entry from the book based on index
Parameters: index (Int) – The index of the entry to be returned Returns: An entry in the book Return type: Entry
- get_entry_index(entry)¶
Get the index of an entry in the book.
Parameters: entry (Entry) – The entry object to be located Returns: The index of the entry Return type: Int
- get_str_entries()¶
Get a list of string representation of all the entries in the book. This is used for displaying entries in the gui.
- import_from(path)¶
Import address from a tsv file
Parameters: path (String) – Path to the file to be imported.
- merge(other)¶
Merge two address books, removing duplicated entries, all the entries are merged into the current book
Parameters: other (Book) – The other book to be merged with the current one
- search(string, field=None)¶
Search all the entries containing a specific string in the address book
Parameters: string (String) – the string to be searched Returns: A list of entries containing the string Return type: List
- set_entries(entries)¶
Replace the current list of entries in the book with a new one.
Parameters: entries (List) – The new list of entries
- show_entry()¶
Print all the entries in the book
- sort(attr)¶
Sort the entries based on one of the attributes
Parameters: attr (String) – The attribute to be based on
- class address.Entry(fname='', lname='', addr='', city='', state='', zip_code='', phone_num='', email='', **kwargs)¶
A class representing an entry in an address book
- get_attr(attr)¶
Get the value associated with a field name. :arg attr: The attribute of the entry to be returned :type attr: String
Returns: The value associated with attr. Return type: String Raises KeyError: when trying to get a field that does not exist.
- gui_str()¶
- set_attr(attr, value)¶
Edit an attribute in the entry
Parameters: - attr (String) – The attribute of the entry to be edited
- value (String) – The new value for the target attribute
Raises KeyError: when trying to set a field that does not exist.
- to_postal()¶
Generates a postal address which conforms usps postal format. The result is a list of strings, and each string represents one line in postal address.
Returns: A list of strings Return type: List