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.

  1. Create a new file and name it string_definitions-b.py.
  2. 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 ...

Get Python 2.6 Text Processing Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.