Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42688

Re: Mixin way?

From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Mixin way?
Date 2013-04-03 17:16 +0000
Organization Norwich University
Message-ID <as36enFrk8aU1@mid.individual.net> (permalink)
References <mailman.60.1364997899.3114.python-list@python.org> <515c4f07$0$29966$c3e8da3$5496439d@news.astraweb.com> <mailman.64.1365006544.3114.python-list@python.org>

Show all headers | View raw


On 2013-04-03, andrea crotti <andrea.crotti.0@gmail.com> wrote:
> Well I can explain better the situation to make it more clear.
>
> We are using CouchDb and so far it has been (sigh) a brutal
> manipulation of dictionaries everywhere, with code duplication
> and so on.
>
> Now I wanted to encapsulate all the entities in the DB in
> proper objects, so I have a CouchObject:
>
>
> class CouchObject(object) :
>     """
>     Encapsulate an object which has the ability to be saved to a couch
>     database.
>     """
>     #: list of fields that get filled in automatically if not passed in
>     AUTO = ['created_datetime', 'doc_type', '_id', '_rev']
>     #: dictionary with some extra fields with default values if not
>     # passed in the constructor the default value gets set to the attribute
>     DEFAULTS = {}
>     REQUIRED = []
>     OPTIONAL = []
>     TO_RESOLVE = []
>     MIXINS = []
>
> Where every subclass can redefine these attributes to get
> something done automatically by the constructor for
> convenience.

Hopefully someone with experience with them can help you further,
but this seems like a job for a metaclass.

-- 
Neil Cerutti

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Mixin way? andrea crotti <andrea.crotti.0@gmail.com> - 2013-04-03 15:04 +0100
  Re: Mixin way? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-03 15:47 +0000
    Re: Mixin way? andrea crotti <andrea.crotti.0@gmail.com> - 2013-04-03 17:29 +0100
      Re: Mixin way? Neil Cerutti <neilc@norwich.edu> - 2013-04-03 17:16 +0000

csiph-web