Enums and Python

Dave Thomas Dave at Thomases.com
Wed Jun 21 10:30:21 EDT 2000


"William Dandreta" <wjdandreta at worldnet.att.net> writes:

> fields = splitfields(line,',')
> 
> fields[Date][:5]  is the year
> 
> is more obvious and less cryptic than
> 
> fields[1][:5]

There have been many fine answers to this, but they all seem to me to
miss the point ;-)

The data you are reading is is not a list, it just happens to have
been stored as delimited strings externally. In reality, the data is
structured. So the OO solution would be to create a class to represent
this information and encapsulate the knowledge of the external
representation in that class. That way you don't have globals
containing magic numbers.

  timeRecord = TimeRecord(line)

  print timeRecord.date()

etc...


Regards


Dave

 ___________________________________________________________________________
| The Pragmatic Programmers, LLC     |  http://www.pragmaticprogrammer.com  |
| Read "The Pragmatic Programmer"    |  www.pragmaticprogrammer.com/ppbook/ |
 ---------------------------------------------------------------------------






More information about the Python-list mailing list