Enums and Python

Aahz Maruch aahz at netcom.com
Wed Jun 21 09:54:43 EDT 2000


In article <ShZ35.11603$Uw3.753134 at bgtnsc04-news.ops.worldnet.att.net>,
William Dandreta <wjdandreta at worldnet.att.net> wrote:
>
>What I am doing is reading a comma delimited text file like this
>
>line = AB12345,20000621,3.56,...
>
>fields = splitfields(line,',')
>
>recognizing that
>
>fields[Date][:5]  is the year
>
>is more obvious and less cryptic than
>
>fields[1][:5]
>
>Trying to put this into a dictionary seems a contrivance to me that doesn't
>make things clearer and only adds overhead.

Sure, but at this point you're not using an enum in the narrow sense;
you're using an enum as a substitute for getting what you want.  What
you should really be doing in this case, probably, is writing a function
that copies the fields into a dict.  Then you can use fields['Date'][:5]
and the rest of your code will work even if the data layout changes.
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"This is Usenet.  We're all masturbating in public places."  -DH



More information about the Python-list mailing list