[Tutor] Looking at a String as a Struct?

W W srilyk at gmail.com
Thu Sep 11 13:19:06 CEST 2008


On Thu, Sep 11, 2008 at 5:58 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net>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?
>

My guess is you really want to use a dict. Perhaps a list of dicts... or a
dict of lists.

Some combination of the two should give you the functionality you're looking
for.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080911/f5d26860/attachment.htm>


More information about the Tutor mailing list