On Thu, Sep 11, 2008 at 6:58 AM, Wayne Watson <[EMAIL PROTECTED]> wrote: > Is it possible in Python to look at a string as a "struct". I don't think a > struct exists in python. Actually, is there something analogous to a record. > In the case of strings, suppose I have string that is composed of > sub-strings like, first_name, last-name, date_of birth, which consists of > month, day, and year, and finally SSN, street_address, state, city, and > zip_code. I'd like to access these fields directly instead of lastname = > record[38:55]. What if fields are not just strings, but some numeric values?
For numeric fields, just convert as needed: quantity = int(record[55:60]) price = float(record[60::70]) If the numbers are binary, rather than ascii, see the struct module. Kent _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
