文件操作 - ipstruct.cpython-311.pyc
返回文件管理
返回主菜单
删除本文件
文件: /usr/lib/python3/dist-packages/ipython_genutils/__pycache__/ipstruct.cpython-311.pyc
编辑文件内容
� ��X�+ � �, � d Z dgZ G d� de� � ZdS )zyA dict subclass that supports attribute style access. Can probably be replaced by types.SimpleNamespace from Python 3.3 �Structc �n � e Zd ZdZdZd� Zd� Zd� Zd� Zd� Z d� Z d � Zd � Zd� Z d� Zd � Zd� Zdd�Zdd�ZdS )r aY A dict subclass with attribute style access. This dict subclass has a a few extra features: * Attribute style access. * Protection of class members (like keys, items) when using attribute style access. * The ability to restrict assignment to only existing keys. * Intelligent merging. * Overloaded operators. Tc �h � t � | dd� � t j | g|�R i |�� dS )a� Initialize with a dictionary, another Struct, or data. Parameters ---------- args : dict, Struct Initialize with one dict or Struct kw : dict Initialize with key, value pairs. Examples -------- >>> s = Struct(a=10,b=30) >>> s.a 10 >>> s.b 30 >>> s2 = Struct(s,c=30) >>> sorted(s2.keys()) ['a', 'b', 'c'] � _allownewTN)�object�__setattr__�dict�__init__)�self�args�kws �;/usr/lib/python3/dist-packages/ipython_genutils/ipstruct.pyr zStruct.__init__ sB � �, ���4��d�3�3�3�� �d�(�T�(�(�(�R�(�(�(�(�(� c �x � | j s|| vrt d|z � � �t � | ||� � dS )a{ Set an item with check for allownew. Examples -------- >>> s = Struct() >>> s['a'] = 10 >>> s.allow_new_attr(False) >>> s['a'] = 10 >>> s['a'] 10 >>> try: ... s['b'] = 20 ... except KeyError: ... print('this is not allowed') ... this is not allowed z8can't create new attribute %s when allow_new_attr(False)N)r �KeyErrorr �__setitem__)r �key�values r r zStruct.__setitem__3 sR � �&