當前位置: 首頁>>代碼示例>>Python>>正文


Python OrderedDict.__getitem__方法代碼示例

本文整理匯總了Python中collections.OrderedDict.__getitem__方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.__getitem__方法的具體用法?Python OrderedDict.__getitem__怎麽用?Python OrderedDict.__getitem__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在collections.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.__getitem__方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
        """Get items from a TableColumns object."""
        if isinstance(item, six.string_types):
            try:
                return OrderedDict.__getitem__(self, item)
            except KeyError:
                try:
                    return OrderedDict.__getitem__(self, item.lower())
                except KeyError:
                    return OrderedDict.__getitem__(self, item.upper())

        elif isinstance(item, int):
            return self.values()[item]
        elif isinstance(item, tuple):
            return self.__class__([self[x] for x in item])
        elif isinstance(item, slice):
            return self.__class__([self[x] for x in list(self)[item]])
        else:
            raise IndexError('Illegal key or index value for {} object'
                             .format(self.__class__.__name__)) 
開發者ID:telegraphic,項目名稱:fits2hdf,代碼行數:22,代碼來源:idi.py

示例2: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
        """Get items from a TableColumns object.
        ::

          tc = TableColumns(cols=[Column(name='a'), Column(name='b'), Column(name='c')])
          tc['a']  # Column('a')
          tc[1] # Column('b')
          tc['a', 'b'] # <TableColumns names=('a', 'b')>
          tc[1:3] # <TableColumns names=('b', 'c')>
        """
        if isinstance(item, str):
            return OrderedDict.__getitem__(self, item)
        elif isinstance(item, (int, np.integer)):
            return self.values()[item]
        elif (isinstance(item, np.ndarray) and item.shape == () and item.dtype.kind == 'i'):
            return self.values()[item.item()]
        elif isinstance(item, tuple):
            return self.__class__([self[x] for x in item])
        elif isinstance(item, slice):
            return self.__class__([self[x] for x in list(self)[item]])
        else:
            raise IndexError('Illegal key or index value for {} object'
                             .format(self.__class__.__name__)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:25,代碼來源:table.py

示例3: get

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def get(self, key):
        """ Basic getter that renews LRU status upon inspection

        Args:
            key (str): immutable dictionary key
        """

        value = OrderedDict.__getitem__(self, key)
        self.move_to_end(key)
        return value 
開發者ID:betteridiot,項目名稱:bamnostic,代碼行數:12,代碼來源:utils.py

示例4: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
        if type(item) is list:
            return self.reverse[item[0]]
        else:
            return dict.__getitem__(self, item) 
開發者ID:SrikanthVelpuri,項目名稱:tf-pose,代碼行數:7,代碼來源:pgcollections.py

示例5: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
        try:
            return OrderedDict.__getitem__(self, key)
        except KeyError:
            return self.__missing__(key) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:7,代碼來源:__init__.py

示例6: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):

        key = key.lower()  # all keys should be lower-case to make editing easier

        try:
            return OrderedDict.__getitem__(self, key)
        except KeyError:
            return self.__missing__(key) 
開發者ID:geographika,項目名稱:mappyfile,代碼行數:10,代碼來源:ordereddict.py

示例7: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self: Dict[CacheKey, CacheValue], key: CacheKey) -> CacheValue:
        """Gets the item, but also makes it most recent."""
        value: CacheValue = OrderedDict.__getitem__(self, key)
        OrderedDict.__delitem__(self, key)
        OrderedDict.__setitem__(self, key, value)
        return value 
開發者ID:willmcgugan,項目名稱:rich,代碼行數:8,代碼來源:_lru_cache.py

示例8: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
        if OrderedDict.__contains__(self, key):
            val = OrderedDict.__getitem__(self, key)
        elif '.' in key:
            keys = key.split('.')
            val = self[keys[0]]
            for k in keys[1:]:
                val = val[k]
        else:
            return OrderedDict.__getitem__(self, key)
        return val 
開發者ID:Cadene,項目名稱:bootstrap.pytorch,代碼行數:13,代碼來源:options.py

示例9: __contains__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __contains__(self, key):
        # Cannot use "key in" due to recursion, reusing rules for dotted keys from __getitem__
        try:
            self[key]
            return True
        except KeyError:
            return False 
開發者ID:Cadene,項目名稱:bootstrap.pytorch,代碼行數:9,代碼來源:options.py

示例10: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key, *args, **kwargs):
            # Get the key and remove it from the cache, or raise KeyError
            value = OrderedDict.__getitem__(self, key)
            del self[key]

            # Insert the (key, value) pair on the front of the cache
            OrderedDict.__setitem__(self, key, value)

            # Return the value from the cache
            return value 
開發者ID:sriniiyer,項目名稱:codenn,代碼行數:12,代碼來源:utils.py

示例11: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, key):
        if isinstance(key, (int, slice)):
            return super(EnrichedTuple, self).__getitem__(key)
        else:
            return self.__getitem_hook__(key) 
開發者ID:devitocodes,項目名稱:devito,代碼行數:7,代碼來源:data_structures.py

示例12: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __getitem__ [as 別名]
def __getitem__(self, item):
        e = OrderedDict.__getitem__(self, item)
        del self[item]
        OrderedDict.__setitem__(self, item, e)
        return e 
開發者ID:JoinMarket-Org,項目名稱:joinmarket-clientserver,代碼行數:7,代碼來源:cryptoengine.py


注:本文中的collections.OrderedDict.__getitem__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。