librelist archives

« back to archive

use extended dict as app config

use extended dict as app config

From:
.:: Mehdi Bayazee ::.
Date:
2011-09-05 @ 07:44
hi
App.config is a class based on dict object.
So we must use it as a dict later and all settings in it accessed same as a
dict.

like:
app.config['DEBUG']

But i think it will be good to it can be accessed such as a class.

app.config.DEBUG

it can be down by some simple overrided methods. i write simple code for
this:

class EDict(dict):

    def __init__(self, **kwargs):

        for key, value in kwargs.iteritems():

            self.__setitem__(key, value)



        dict.__init__(self)



    def __getattr__(self, attr):

        return super(EDict, self).__getitem__(attr)



    def __setattr__(self, attr, value):

        self[attr] = value



    def __delattr__(self, key):

        return super(EDict, self).__delitem__(key)

-- 
Regards,
Mehdi Bayazee

Re: [flask] use extended dict as app config

From:
Armin Ronacher
Date:
2011-09-05 @ 11:25
Hi,

On 2011-09-05 9:44 AM, .:: Mehdi Bayazee ::. wrote:
> So we must use it as a dict later and all settings in it accessed same
> as a dict.
For good reasons :-)

> But i think it will be good to it can be accessed such as a class.
>
> app.config.DEBUG
>
> it can be down by some simple overrided methods. i write simple code for
> this:
And because it's simple you can easily do that yourself.  We don't want 
to have this kind of "magic" in Flask itself.  There should only be one 
way to access things.


Regards,
Armin