top of page

Python scripts can be used to add returns between multiple strings that are separated with unequal blank spaces. The resulting list will have the extra spaces excised. This task is accomplished with the split function.

Working in Python 2.7, follow these steps.

1. Assign a name to the text to be parsed. In this example, we call the text 'set1'

>>> set1 = "Lopez Lee Smith"

2. Create a second set (here it's called 'names'), and then use the split function with no setting between the parentheses that follow the function name. The name of what we're parsing precedes the split function. >>> names = set1.split()

3. Python will understand a reference to a single member of a set with a plural name. Use this command: >>> for name in names:

. . . and then press return and print the reference to the set with the singular name. print name

Press return twice to get the results:

Lopez Lee Smith >>>



Here's a simple guide to accessing Excel files with Python. I'm working with Python 2.7 here.

First in Windows command prompt, in the directory containing your Python scripts (see for example, C:\Python27\Scripts), run two modules:

pip install xlrd

pip install xlwt

Then in the IDLE (Python GUI) program enter the below script.

1. Import the xlrd module

>>> import xlrd

2. open the workbook

>>> book = xlrd.open_workbook("C:\FooFolder\python\BattingPost.xls")

3. designate the worksheet you want to work with

>>> sheet = book.sheet_by_name("BattingPost")

4. to pull data from a particular cell, assign a name to the cell.

>>> playerid = sheet.cell_value(2,2)

5. the value of the assigned name can be displayed by using the print command.

>>> print playerid

>>> import xlrd >>> book = xlrd.open_workbook("C:\FooFolder\python\BattingPost.xls") >>> sheet = book.sheet_by_name("BattingPost") >>> playerid = sheet.cell_value(2,2) >>> print playerid bradyst01

This is a view of the spreadsheet I pulled data from.


Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page