Dictonary persistance weirdness

John Machin sjmachin at lexicon.net
Sun Apr 10 21:46:20 EDT 2005


On Sun, 10 Apr 2005 19:07:23 -0300, Gonzalo Sainz-Trápaga (GomoX)
<gomoSINSPAM at datafull.com> wrote:

>-- wrappers.py -------------------------
>class VarsWrapper:
>    def __init__(self,req):
>        self.fs = util.FieldStorage(req)
>
>    def get_vars():
>        d = {}
>        for each in self.fs.list:
>            self.d[x.name] = x.value
>        return d
>

Are you sure that is the code that you are executing? What is "x"?
What is "self.d"? "each" is not used. Even if "x" and "self.d" do
exist, the for loop will do nothing, and the method will return an
empty dictionary.

You weren't trying to "optimise" the references to self.d inside the
loop, were you?

Making the charitable assumptions that d and self.d are the same thing
and so are "x" and "each":

Assuming self.d does exist, why does it exist? I.e for what reason do
you want the data to persist? Could its persistence be the cause of
your problem? Are you sure you are not accidentally always referring
to the same VarsWrapper instance?

Is that all that VarsWrapper contains? Seems to me like an unnecessary
and possibly confusing convolution. If you "own" util.FieldStorage,
then giving it an as_dictionary() method might be a good idea.
Otherwise a simple wrapper *function* that replaces your two-step
__init__ and get_vars would be a not unreasonable idea; there's no law
that says that everything must be a class. 

Are you sure you don't have a dict as a default arg somewhere, like in
def handle(self, vars={})  ??

HTH,

John




More information about the Python-list mailing list