Problem of Readability of Python

Paul McGuire ptmcg at
Sun Oct 7 23:24:32 CEST 2007

On Oct 7, 1:07 pm, Licheng Fang <fanglich... at> 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.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?

"""Just use a single empty class (such as the AttributeContainer
   and then use different instances of the class for different sets
   of name/value pairs.  (This type of class also goes by the name
   but that name is too, um, nondescript for me.)  You can see from
   example that there is no requirement for names to be shared,
   common, or unique.

   -- Paul"""

class AttributeContainer(object):

a = AttributeContainer() = "Lancelot"
a.favorite_color = "blue"

b = AttributeContainer() = "European swallow"
b.laden = true
b.airspeed = 20

More information about the Python-list mailing list