Time for action - simple manipulation with string methods
In this example, we'll extend our little employee data-gathering script present earlier in the chapter. The goal is to illustrate the use of some of the string object methods.
- Create a new file and name it
- Enter the following code:
import sys class BadEmployeeFormat(Exception): """Badly formatted employee name""" def __init__(self, reason, name): Exception.__init__(self, reason) self.name = name def get_employee(): """ Retrieve user information. This method simply prompts the user for an employee's name and his current job title. """ employee = raw_input('Employee Name: ') role = raw_input("Employee's Role: ") employee, role = employee.strip(), role.strip() # Make ...