using converters, adapters in sqlite3

2006-11-15 Thread matthewperpick
hello,

i want to make use of sqlite3's "adapter" and "converter" capabilities
but my classes are more complex than the point examples in the python
documentation (http://docs.python.org/lib/node347.html), because they
include foreign keys to othe rtables.

I don't want to concatenate those with the class' other data in one
column because then I lose the ability to filter data by FK in my
select queries.

so .. I was hoping someone could show me how to write converters &
adapters that will allow me to each attribute in its own column.

Thanks very much,

Matt

-- 
http://mail.python.org/mailman/listinfo/python-list


strange behaviour with keyword arguments and inheritance

2007-04-16 Thread matthewperpick
Check out this toy example that demonstrates some "strange" behaviour
with keyword arguments and inheritance.

=

class Parent:
def __init__(self, ary = []):
self.ary = ary

def append(self):
self.ary.append(1)

class Child(Parent):
def __init__(self):
Parent.__init__(self)
self.append()

def main():
a = Child()
print a.ary
b = Child()
print b.ary

main()

=

You would think the output of this program would be [1], [1]. But
strangely enough the output is [1,], [1,1]. I suppose that the
Parent.__class__ object is only created once and thus the keyword
argument always refers to the same thing, but I don't know. I have a
very rudimentary understading of python's guts, but I would still call
the behaviour unexpected. Or perhaps I should rtfm?

Any thoughts would be much appreciated. Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: strange behaviour with keyword arguments and inheritance

2007-04-17 Thread matthewperpick
cool .. thanks everyone. here is the aforementioned faq.

http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects

On Apr 17, 5:16 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> matthewperpick wrote:
> > Check out this toy example that demonstrates some "strange" behaviour
> > with keyword arguments and inheritance.
>
> > =
>
> > class Parent:
> > def __init__(self, ary = []):
> > self.ary = ary
>
> [snip]
>
> As pointed out earlier, default values for arguments are evaluated
> when the function is defined, not when it is called.  This creates
> confusion if this value is mutable and later mutated; I got confused
> by it when I started python.  So it is often not a good idea to use
> mutable objects as default arguments.
>
> A simple fix:
>
> def __init__(self, ary=None):
> if ary is None: ary = []
>self.ary = ary
>
> --
> Arnaud


-- 
http://mail.python.org/mailman/listinfo/python-list