Enums and Python

William Dandreta wjdandreta at worldnet.att.net
Wed Jun 21 12:16:34 EDT 2000


Hi Martijn,

This suggestion is the most appealing to me for what I am doing because I
always know exactly how many fields there are.

Now if there were just some way to similarly name a slice...

Bill

>In many cases I'd use tuple/list unpacking for this:
>
>date, address, name, whatever = string.split(line, ",")
>
>If you don't know how many fields you're going to get, this can be
>more tricky. But imagine you know the first 4:
>
>date, address, name, whatever = string.split(line, ",")[:4]
>
>Of course changing a field is harder here. Generally I use the idiom of
>constructing new lists (or dictionaries or objects) in that case,
>though. After all, if you're really going to manipulate your fields
>it makes sense to wrap them up in objects in any case.
>
>Regards,
>
>Martijn








More information about the Python-list mailing list