python classes

William D. Gill wmgill at
Thu Mar 4 20:42:07 CET 2004

"Peter Otten" <__peter__ at> wrote in message
news:c27t0v$fhn$05$1 at
> William D. Gill wrote:
> > class MyClass:
> >     def __init__(self, id=0000):
> > = MyOtherClass(id)    # data is an object with name,
> > and other properties
> I think this is an extra complication that gains you nothing. The only
> exception would be that data would not be initialized in
> but lazily at some later point, a usefull pattern if for a significant
> of the MyClass instances you can get away with not initializing data at
> all. You would then change MyClass as follows:
My thinking was to create a class for each table that contains pieces of the
whole customer information , and wrap OOPS! I mean include :)  those classes
in the overall customer class object.  That way by supplying id, all the
different constructors would go get the right data.

At my level (pre-novice) it's probably better to use one customer class and
sequential programming in the constructor:

select * from table A where id=1234
self.company_name =

select * from table B where id=1234
self.billto = B.billto
select * from table C where id=1234
(using multiple selects because they may produce different size record sets)

> I suppose that was a mutual misunderstanding. Did you mean this by
> "wrapping"?
> try:
>     customer = Customer.fromId(1234)
> except InvalidCustomer, e:
>     print e


More information about the Python-list mailing list