Home > Backend Development > Python Tutorial > python创建只读属性对象的方法(ReadOnlyObject)

python创建只读属性对象的方法(ReadOnlyObject)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 11:28:09
Original
1759 people have browsed it

代码如下:


def ReadOnlyObject(**args):
    dictBI = {}
    args_n = []
    for name, val in args.items():
        dictBI[name] = val
        args_n.append(name)
    dictBI['__slots__'] = args_n
    return type('ReadOnlyObject', (object,), dictBI)()

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template