June 2002
Beginner to intermediate
640 pages
14h 24m
English
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 ...
Read now
Unlock full access