Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

access dict elements with dot

class dotdict(dict):
    """dot.notation access to dictionary attributes"""
    __getattr__ = dict.get
    __setattr__ = dict.__setitem__
    __delattr__ = dict.__delitem__
Comment

access dict elements with dot


class Map(dict):
    """
    Example:
    m = Map({'first_name': 'Eduardo'}, last_name='Pool', age=24, sports=['Soccer'])
    """
    def __init__(self, *args, **kwargs):
        super(Map, self).__init__(*args, **kwargs)
        for arg in args:
            if isinstance(arg, dict):
                for k, v in arg.iteritems():
                    self[k] = v

        if kwargs:
            for k, v in kwargs.iteritems():
                self[k] = v

    def __getattr__(self, attr):
        return self.get(attr)

    def __setattr__(self, key, value):
        self.__setitem__(key, value)

    def __setitem__(self, key, value):
        super(Map, self).__setitem__(key, value)
        self.__dict__.update({key: value})

    def __delattr__(self, item):
        self.__delitem__(item)

    def __delitem__(self, key):
        super(Map, self).__delitem__(key)
        del self.__dict__[key]

Comment

PREVIOUS NEXT
Code Example
Typescript :: missing return type on function @typescript-eslint/explicit-function-return-type 
Typescript :: corpses:2249 Livewire: The published Livewire assets are out of date 
Typescript :: stats normal 
Typescript :: how to bold to custom fonts on Online 
Typescript :: add padding between elements of lazyrow jetpack compose 
Typescript :: which network device reads the source and destination MAC addresses, looks up the destination to determine where to send the frame, and forwards it out to the correct port 
Typescript :: typescript generic object not array 
Typescript :: wordpress posts sidebar with category link programmatically 
Typescript :: what do you need local sccripts for 
Typescript :: react native websocket disconnect handler 
Typescript :: how to assert element attributes in mocha js 
Typescript :: cannot find name describe jasmine 
Typescript :: pretty print json file cmd 
Typescript :: phase on load complete 
Typescript :: summary of investigation in contemporary world 
Typescript :: nest js config from yaml 
Typescript :: React Draft Wysiwyg typescript 
Typescript :: call appply bind 
Typescript :: multi select + search + Multiselect and Search in angular 13 
Typescript :: les différents types de cours 
Typescript :: searching filtering ibraries in angular 
Typescript :: fieldmatch cannot be resolved to a type 
Typescript :: cluster on lists of values that start with a certain value 
Typescript :: best esports game ever 
Typescript :: typescript declare "userLanguage" 
Typescript :: Unhandled promise rejection: TypeError: ImagePicker.requestMediaLibraryPermissionsAsync is not a function. 
Typescript :: change css to scss in angular online 
Typescript :: which of the foolowing ia an element of pallette that holds multiple elements of nspecific purpose 
Typescript :: ioredis 
Typescript :: top data scientists in the world 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =