The Power of Python

Python can make tough tasks trivial. Let's prove this by an example. How many lines of code will it take you in your favorite language to parse the following string and put each value in a variable?

>>> str = "Rick Hightower, 555-1212,rick_m_hightower@emailcompany.com

Can you parse it in ten lines? Maybe five? Python can do it in one (not including the import statement).

>>>from string import split
>>>name, phone, email = split(str, ",")

This is what we get:

>>> print name
Rick Hightower
>>> print phone
 555-1212
>>> print email
 rick_m_hightower@emailcompany.com
>>>

Simple parsing using the split() function is covered in Chapter 10; more advanced parsing using regular expressions is covered in Appendix E.

Here's an easy ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.