当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.iteritems方法代码示例

本文整理汇总了Python中odict.OrderedDict.iteritems方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.iteritems方法的具体用法?Python OrderedDict.iteritems怎么用?Python OrderedDict.iteritems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在odict.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.iteritems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __add__

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import iteritems [as 别名]
    def __add__(self,rhs):
        "Add histograms in rhs to current sample and create a new sample"
        s = self.Clone()

        print 'Plotter ### in add for Label = ', self.Label
        # Deal with samples not having hists (e.g. files not found)
        if len(rhs._HistDict)==0: return s
        if len(s._HistDict)==0:   return rhs

        #make copies so elements can be removed without lasting damage
        RhsHistDict = rhs._HistDict
        SHistDict   = s._HistDict

        # make a new OrderedDict that contains only the hists that are in both rhs and self and fill it with those in self
        MinHistDict = OrderedDict()
        for key, obj in SHistDict.iteritems():
            if SHistDict.has_key(key) and RhsHistDict.has_key(key): MinHistDict[key]=obj

        if testVerbose: print 'Sample ### MinHistDict = ', MinHistDict

        #now add rhs to the new ordered dict
        for key, obj in MinHistDict.iteritems():
            MinHistDict[key].Add(RhsHistDict[key])

        self._OpSetProperties(s, rhs, '+')

        #alter the hist dict of copy of self by setting it to the new hist dict created above and return it
        s._HistDict = MinHistDict
        return s
开发者ID:RFQED,项目名称:g-2_Plotting,代码行数:31,代码来源:Sample.py

示例2: __init__

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import iteritems [as 别名]
class Domain:

    def __init__(self, name):
        self.name = name
        self.sensitivities = OrderedDict()
        self.baseClassifications = OrderedDict()
        self.rawToTrans = OrderedDict()
        self.transToRaw = OrderedDict()
        self.groups = OrderedDict()

    def addSensitivity(self, sensitivity, level):
        if self.sensitivities.has_key(sensitivity) == 0:
            self.sensitivities[sensitivity] = level

    def findSensitivityByName(self, sensitivity):
        for k, v in self.sensitivities.iteritems():
#            print k,v
            if v == sensitivity:
                return sensitivity
        return None
        

    def addGroup(self, groupName):
        group = Group(groupName)
        self.groups[groupName] = group
        return group

    def addBaseClassification(self, bcName):
        baseClassification = BaseClassification(bcName)
        self.baseClassifications[bcName] = baseClassification
        return baseClassification

    def str(self):
        str = ""
        str = str + "Domain name: %s\n" % (self.name)
        str = str + "Sensitivities:"
        for key in self.sensitivities.keys():
            str = str + "%s %s\n" % (key, self.sensitivities[key])
        str = str + "Base classifications:\n"
        for key in self.baseClassifications.keys():
            str = str + str(self.baseClassifications[key])
        str = str + "Groups:\n"
        for key in self.groups.keys():
            str = str + str(self.groups[key])
#        str = str + "Raw to translated:"
#        for key in self.rawToTrans.keys():
#            str = str + "%s %s" % (key, self.rawToTrans[key])
#        str = str + "Translated to raw:"
#        for key in self.transToRaw.keys():
#            str = str + "%s %s" % (key, self.transToRaw[key])
        return str
开发者ID:tedx,项目名称:mls-tools,代码行数:53,代码来源:mcstrans.py

示例3: Sample

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import iteritems [as 别名]
class Sample(object):
    """
    Implementation of a Sample object which a set of histograms from a file along with specified
    style and plotting attributes.  Samples can be added, subtracted, divided and multiplied and 
    are iterable (iterating over the stored histograms)
    
    Example:
    
    s = Sample(FileName     = 'file.root',
               Label        = 'Data',
               Type         = 'e',
               MarkerColour = 2)
                       
    A particular histogram can be retrived by Get('histname') or printed to file via Draw('histname')

    """
    if testVerbose: print '### in sample', '\n' 

    # Object (rather than instance) variables relavent to all Sample objects
    CutHist     =  ''
    Lumi        =  None   # fb -l
    OutputLevel = INFO    # Default logging level for all samples; will be overriden if set on individual sample
    
    def __init__(self, sample=None, **kwargs):
        """
        Initalise sample object from a set of keyword arguments, or alternatively another sample
        object.  Create the TFile and extract the histograms into the local data structure

        """

        if testVerbose: print 'Sample ### in __init__, kwargs = ', kwargs, 'sample = ', sample
        
        self.FileName    = ''
        self.OutputLevel = Sample.OutputLevel
        self.Label       = 'Data'
        self.Legend      = ''
        self.Type        = ''
        self.Type2D      = ''
        self.TypeGraph   = 'apl'
        self.LineColour  = 0
        self.LineStyle   = 1
        self.LineWidth   = 1        
        self.MarkerColour= 0        
        self.MarkerStyle = 1
        self.MarkerSize  = 0.5
        self.FillStyle   = 0
        self.FillColour  = 0
        self.Scale       = 1        
        self.Sumw2       = False
        self.Normalise   = False
        self.Batch       = True
        self.RemoveDirPatternFromName = False
        self.OnlyLoadPattern = False
        self.DivideOpt   = ''
        self.LegendOpt   = ''
        self.Pattern     = None
        self.File        = None
        self._HistDict   = OrderedDict() #{}
        self._Regexp     = None
        self.XSect       = None
        self.IsData      = False
        self.NonCumul    = False
        self.Dummy       = False
        self.Original    = {}

        # Default init
        # if not sample and not kwargs:
        #     return

        # Consistency
        if sample and kwargs:
            log.error("Cannot supply both a sample class and key-word arguments")
            syd.exit(1)

        if testVerbose: print 'Sample ### passed consistency check'

        
        # Copy init (must Clone the histograms)
        if sample and isinstance(sample, Sample):
            for k, v in sample.__dict__.iteritems(): 
                if not k == '_HistDict':
                    setattr(self, k, v)
                else:
                    # Clone all histograms
                    self._HistDict = OrderedDict() #{}
                    for hkey, hval in getattr(sample, k).iteritems():
                        self._HistDict[hkey] = hval.Clone()                
            return 

        if testVerbose: print 'Sample ### overwriting explicitly set key word arguments, before kwargs.items = ', kwargs.items()
        # Overwrite attributes explicitly set
        for k, v in kwargs.items():
            setattr(self, k, v)  #equivalent to self.k = v
        if testVerbose: print 'Sample ### overwriting explicitly set key word arguments, after kwargs.items = ', kwargs.items()
            
        if testVerbose: print 'Sample ### calling _Batch()'
        # Load file and extract hists
        self._Batch()   # makes sure the hists don't all just pop up at once, i think
        TH1.AddDirectory(False);

#.........这里部分代码省略.........
开发者ID:RFQED,项目名称:g-2_Plotting,代码行数:103,代码来源:Sample.py


注:本文中的odict.OrderedDict.iteritems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。