Problem of Readability of Python

Kevin wyldwolf at gmail.com
Wed Oct 10 12:28:15 EDT 2007


Am I missing something, or am I the only one who explicitly declares
structs in python?

For example:
FileObject = {
    "filename" : None,
    "path" : None,
    }

fobj = FileObject.copy()
fobj["filename"] = "passwd"
fobj["path"] = "/etc/"

Kevin Kelley

On 10/7/07, Licheng Fang <fanglicheng at gmail.com> wrote:
> Python is supposed to be readable, but after programming in Python for
> a while I find my Python programs can be more obfuscated than their C/C
> ++ counterparts sometimes. Part of the reason is that with
> heterogeneous lists/tuples at hand, I tend to stuff many things into
> the list and *assume* a structure of the list or tuple, instead of
> declaring them explicitly as one will do with C structs. So, what used
> to be
>
> struct nameval {
>     char * name;
>    int val;
> } a;
>
> a.name = ...
> a.val = ...
>
> becomes cryptic
>
> a[0] = ...
> a[1] = ...
>
> Python Tutorial says an empty class can be used to do this. But if
> namespaces are implemented as dicts, wouldn't it incur much overhead
> if one defines empty classes as such for some very frequently used
> data structures of the program?
>
> Any elegant solutions?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Kevin Kelley
http://technogeek.org/



More information about the Python-list mailing list