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


Python __builtin__.dict方法代码示例

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


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

示例1: openscope

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def openscope(self, customlocals=None):
        '''Opens a new (embedded) scope.

        Args:
            customlocals (dict): By default, the locals of the embedding scope
                are visible in the new one. When this is not the desired
                behaviour a dictionary of customized locals can be passed,
                and those locals will become the only visible ones.
        '''
        self._locals_stack.append(self._locals)
        self._globalrefs_stack.append(self._globalrefs)
        if customlocals is not None:
            self._locals = customlocals.copy()
        elif self._locals is not None:
            self._locals = self._locals.copy()
        else:
            self._locals = {}
        self._globalrefs = set()
        self._scope = self._globals.copy()
        self._scope.update(self._locals) 
开发者ID:aradi,项目名称:fypp,代码行数:22,代码来源:fypp.py

示例2: _check_value_recursively

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def _check_value_recursively(key, val, haystack):
    """
    Check if there is key _key_ with value _val_ in the given dictionary.
    ..warning:
        This is geared at JSON dictionaries, so some corner cases are ignored,
        we assume all iterables are either arrays or dicts
    """
    if isinstance(haystack, list):
        return any([_check_value_recursively(key, val, l) for l in haystack])
    elif isinstance(haystack, dict):
        if not key in haystack:
            return any([_check_value_recursively(key, val, d) for k, d in haystack.items()
                        if isinstance(d, list) or isinstance(d, dict)])
        else:
            return haystack[key] == val
    else:
        return False 
开发者ID:ResilienceTesting,项目名称:gremlinsdk-python,代码行数:19,代码来源:assertionchecker.py

示例3: check_assertions

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def check_assertions(self, checklist, all=False):
        """Check a set of assertions
        @param all boolean if False, stop at first failure
        @return: False if any assertion fails.
        """

        assert isinstance(checklist, dict) and 'checks' in checklist

        retval = None
        retlist = []

        for assertion in checklist['checks']:
            retval = self.check_assertion(**assertion)
            retlist.append(retval)
            if not retval.success and not all:
                print "Error message:", retval[3]
                return retlist

        return retlist 
开发者ID:ResilienceTesting,项目名称:gremlinsdk-python,代码行数:21,代码来源:assertionchecker.py

示例4: __init__

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def __init__(self, dict=None, preserve=1):
        """Create an empty dictionary, or update from 'dict'."""
        self.data = {}
        self.preserve=preserve
        if dict:
            self.update(dict) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:8,代码来源:util.py

示例5: update

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def update(self, dict):
        """Copy (key,value) pairs from 'dict'."""
        for k,v in dict.items():
            self[k] = v 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:6,代码来源:util.py

示例6: dict

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def dict(*a, **k):
    import __builtin__
    warnings.warn('twisted.python.util.dict is deprecated.  Use __builtin__.dict instead')
    return __builtin__.dict(*a, **k) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:6,代码来源:util.py

示例7: dict

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def dict(*a, **k):
    import warnings
    import __builtin__
    warnings.warn('twisted.python.util.dict is deprecated.  Use __builtin__.dict instead')
    return __builtin__.dict(*a, **k) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:7,代码来源:util.py

示例8: _get_restricted_builtins

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def _get_restricted_builtins(cls):
        bidict = dict(cls._RESTRICTED_BUILTINS)
        major = sys.version_info[0]
        if major == 2:
            bidict['True'] = True
            bidict['False'] = False
        return bidict 
开发者ID:aradi,项目名称:fypp,代码行数:9,代码来源:fypp.py

示例9: _process_arguments

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def _process_arguments(self, args, keywords):
        kwdict = dict(keywords)
        argdict = {}
        nargs = min(len(args), len(self._argnames))
        for iarg in range(nargs):
            argdict[self._argnames[iarg]] = args[iarg]
        if nargs < len(args):
            if self._varpos is None:
                msg = "macro '{0}' called with too many positional arguments "\
                      "(expected: {1}, received: {2})"\
                      .format(self._name, len(self._argnames), len(args))
                raise FyppFatalError(msg, self._fname, self._spans[0])
            else:
                argdict[self._varpos] = list(args[nargs:])
        elif self._varpos is not None:
            argdict[self._varpos] = []
        for argname in self._argnames[:nargs]:
            if argname in kwdict:
                msg = "got multiple values for argument '{0}'".format(argname)
                raise FyppFatalError(msg, self._fname, self._spans[0])
        if nargs < len(self._argnames):
            for argname in self._argnames[nargs:]:
                if argname in kwdict:
                    argdict[argname] = kwdict.pop(argname)
                elif argname in self._defaults:
                    argdict[argname] = self._defaults[argname]
                else:
                    msg = "macro '{0}' called without mandatory positional "\
                          "argument '{1}'".format(self._name, argname)
                    raise FyppFatalError(msg, self._fname, self._spans[0])
        if kwdict and self._varkw is None:
            kwstr = "', '".join(kwdict.keys())
            msg = "macro '{0}' called with unknown keyword argument(s) '{1}'"\
                  .format(self._name, kwstr)
            raise FyppFatalError(msg, self._fname, self._spans[0])
        if self._varkw is not None:
            argdict[self._varkw] = kwdict
        return argdict 
开发者ID:aradi,项目名称:fypp,代码行数:40,代码来源:fypp.py

示例10: process_file

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def process_file(self, infile, outfile=None):
        '''Processes input file and writes result to output file.

        Args:
            infile (str): Name of the file to read and process. If its value is
                '-', input is read from stdin.
            outfile (str, optional): Name of the file to write the result to.
                If its value is '-', result is written to stdout. If not
                present, result will be returned as string.
            env (dict, optional): Additional definitions for the evaluator.

        Returns:
            str: Result of processed input, if no outfile was specified.
        '''
        infile = STDIN if infile == '-' else infile
        output = self._preprocessor.process_file(infile)
        if outfile is None:
            return output
        if outfile == '-':
            outfile = sys.stdout
        else:
            outfile = _open_output_file(outfile, self._encoding,
                                        self._create_parent_folder)
        outfile.write(output)
        if outfile != sys.stdout:
            outfile.close()
        return None 
开发者ID:aradi,项目名称:fypp,代码行数:29,代码来源:fypp.py

示例11: process_text

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def process_text(self, txt):
        '''Processes a string.

        Args:
            txt (str): String to process.
            env (dict, optional): Additional definitions for the evaluator.

        Returns:
            str: Processed content.
        '''
        return self._preprocessor.process_text(txt) 
开发者ID:aradi,项目名称:fypp,代码行数:13,代码来源:fypp.py

示例12: __init__

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def __init__(self, filename):
        '''
        filename: inits the UBRR data from the input file
        '''
        
        ub_map = dict()
        ub_ratings = dict()
        
        cnt = 0
        
        #read the file
        if filename.endswith('.gz'):
            f = gzip.open(filename, 'r')
        else:
            f = open(filename, 'r')
        
        for line in f:
            vals = line.split("\t")
            if len(vals) == 0:
                continue
            
            u = vals[0]
            b = vals[1]
            r = float(vals[2])
            d = vals[3].strip()
            
            ub_map[(u,b)] = self._int_list(d)
            ub_ratings[(u,b)] = r
            
            cnt += 1
            
        
        self.user_item_map = ub_map
        self.user_item_rating = ub_ratings
        
        
        f.close()
        print 'Data Pair Manager Initialized with ', cnt, ' reviews' 
开发者ID:rosecatherinek,项目名称:TransNets,代码行数:40,代码来源:DataPairMgr.py

示例13: __init__

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import dict [as 别名]
def __init__(self, filename, empty_user = set()):
        '''
        filename: inits the UBRR data from the input file
        empty_user: skip the reviews by this user (keeps the ratings)
        '''
        self.empty_user = empty_user
        
        ur_map = dict()
        br_map = dict()
        
        cnt = 0
        skipped = 0
        
        #read the file
        if filename.endswith('.gz'):
            f = gzip.open(filename, 'r')
        else:
            f = open(filename, 'r')
        
        for line in f:
            vals = line.split("\t")
            if len(vals) == 0:
                continue
            
            u = vals[0]
            b = vals[1]
            r = float(vals[2])
            d = vals[3].strip()
            if u in self.empty_user:
                #we are skipping this review
                d = ''
                skipped += 1
            
            rev = Review(u, b, r, d)  #review obj
            
            
            #store biz -> list of reviews
            if not br_map.has_key(b):
                br_map[b] = []
            
            br_map[b].append(rev)
            
            #store user -> list of reviews
            if not ur_map.has_key(u):
                ur_map[u] = []
                
            ur_map[u].append(rev)
            
            cnt += 1
            
        
        self.biz_map = br_map
        self.user_map = ur_map
        
        
        f.close()
        print 'Review Data Manager Initialized with ', cnt, ' reviews'
        print 'Number of skipped users = ', len(self.empty_user)
        print 'Number of skipped reviews = ', skipped 
开发者ID:rosecatherinek,项目名称:TransNets,代码行数:61,代码来源:DataMgr.py


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