Thursday, 22 August 2013

Assigning multiple variables in Python line-by-line analysis

Assigning multiple variables in Python line-by-line analysis

I'm writing something that analyzes a directory line by line in Python.
Parts of my text follow this format:
SMITH, JOHN
(123) 456-7890
(134) 193-2495
(284) 282-6829
I want to assign the three phone numbers to three different variables
(i.e. phone1, phone2, phone3) all associated with the person John Smith.
I'm thinking of approaching it by testing to see if the variables have
already been assigned. For example, if phone1 already has a phone number
assigned to it, Python knows to assign it to phone2. If phone2 has also
been assigned, then it automatically assigns it to phone3. What's the
easiest way to write something that does this? I'm open to any other
suggestions as well.

No comments:

Post a Comment