Enums and Python
Fred Gansevles
gansevle at cs.utwente.nl
Wed Jun 21 07:00:44 EDT 2000
In article <ShZ35.11603$Uw3.753134 at bgtnsc04-news.ops.worldnet.att.net>,
"William Dandreta" <wjdandreta at worldnet.att.net> wrote:
> Hi Cameron,
>
> 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]
>
If you use enums only as a 'conveniant way to represent values', the
next (quick-hack, untested) might be usefull:
class Enum:
def __init__(self, **kw):
self.__dict__.update(kw)
enum = Enum(Tag = 0, Date = 1, Ammount = 2)
print "Date-field:", enum.Date
--
-----------------------------------------------------------------------
---- Linux/Windows-NT/IntraNetware Administrator ----
-- Whenever it sounds simple, I've probably missed something! ... Me --
-----------------------------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list