• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python msgpack.dump函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中msgpack.dump函数的典型用法代码示例。如果您正苦于以下问题:Python dump函数的具体用法?Python dump怎么用?Python dump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: main

def main(args):
    logging.basicConfig(level=logging.INFO)
    model = json.load(args.ifile)
    fn = fn_from_args(args)
    if fn:
        weight_layers = [layer for layer in model
                         if layer['layerName'] in weight_first_list]
        if fn.needs_two_step:
            for weights in [layer['parameters'][0] for layer in weight_layers]:
                fn.consume(weights)
            fn.done()
        for i, layer in enumerate(weight_layers):
            layer['parameters'][0] = transform(layer['parameters'][0], fn)
        if fn.needs_two_step:
            model = {
                'codebook' : fn.serialize_codebook(),
                'model' : model
            }
    if args.ubjson_format:
        args.ofile.write(simpleubjson.encode(model))
    elif args.json:
        args.ofile.write(json.dumps(model).encode('utf8'))
    else:
        msgpack.dump(model, args.ofile, use_bin_type=True,
                     use_single_float=args.single_precision_float)
    args.ofile.close()
    args.ifile.close()
开发者ID:cupslab,项目名称:neural_network_cracking,代码行数:27,代码来源:msgpacker.py


示例2: freqs_to_cBpack

def freqs_to_cBpack(in_filename, out_filename, cutoff=-600):
    """
    Convert a csv file of words and their frequencies to a file in the
    idiosyncratic 'cBpack' format.

    Only words with a frequency greater than `cutoff` centibels will be
    written to the new file.

    This cutoff should not be stacked with a cutoff in `read_freqs`; doing
    so would skew the resulting frequencies.
    """
    freqs = read_freqs(in_filename, cutoff=0, lang=None)
    cBpack = []
    for token, freq in freqs.items():
        cB = round(math.log10(freq) * 100)
        if cB <= cutoff:
            continue
        neg_cB = -cB
        while neg_cB >= len(cBpack):
            cBpack.append([])
        cBpack[neg_cB].append(token)

    for sublist in cBpack:
        sublist.sort()

    # Write a "header" consisting of a dictionary at the start of the file
    cBpack_data = [{'format': 'cB', 'version': 1}] + cBpack

    with gzip.open(out_filename, 'wb') as outfile:
        msgpack.dump(cBpack_data, outfile)
开发者ID:KadriUmay,项目名称:wordfreq,代码行数:30,代码来源:word_counts.py


示例3: dump

    def dump(data, filepath):
        '''
        Write data as as type self.ext to filepath. json or msgpack
        '''
        if ' ' in filepath:
            raise raeting.KeepError("Invalid filepath '{0}' "
                                    "contains space".format(filepath))

        root, ext = os.path.splitext(filepath)
        if ext == '.json':
            with aiding.ocfn(filepath, "w+") as f:
                json.dump(data, f, indent=2, encoding='utf-8')
                f.flush()
                os.fsync(f.fileno())
        elif ext == '.msgpack':
            if not msgpack:
                raise raeting.KeepError("Invalid filepath ext '{0}' "
                            "needs msgpack installed".format(filepath))
            with aiding.ocfn(filepath, "w+b", binary=True) as f:
                msgpack.dump(data, f, encoding='utf-8')
                f.flush()
                os.fsync(f.fileno())
        else:
            raise raeting.KeepError("Invalid filepath ext '{0}' "
                        "not '.json' or '.msgpack'".format(filepath))
开发者ID:colbygk,项目名称:raet,代码行数:25,代码来源:keeping.py


示例4: crawler_baidu_person_list

def crawler_baidu_person_list():
    # 从百度人气榜上获取人名
    all_person_list = set()
    for index in range(50):
        url = 'http://baike.baidu.com/operation/api/starflowerstarlist?' \
              'rankType=thisWeek&pg=%d' % index
        req = urllib2.Request(url, None)
        response = urllib2.urlopen(req)
        html_doc = response.read()
        content = json.loads(html_doc)
        this_page_list = content.get('data').get('thisWeek')
        for person_content in this_page_list:
            all_person_list.add(person_content.get('name'))
    print len(all_person_list)

    for index in range(50):
        url = 'http://baike.baidu.com/operation/api/starflowerstarlist?' \
              'rankType=lastWeek&pg=%d' % index
        req = urllib2.Request(url, None)
        response = urllib2.urlopen(req)
        html_doc = response.read()
        content = json.loads(html_doc)
        this_page_list = content.get('data').get('lastWeek')
        for person_content in this_page_list:
            all_person_list.add(person_content.get('name'))
    print len(all_person_list)
    all_person_set = list(all_person_list)
    msgpack.dump(all_person_set, open('baidu_fans.p', 'w'))
开发者ID:ustbliubo2014,项目名称:FaceRecognition,代码行数:28,代码来源:person_crawler.py


示例5: crawler_fans

def crawler_fans():
    all_person_set = set()
    f_fans = open('fans.txt', 'w')
    for page_index in range(1, 345, 1):
        for class_index in [1, 2, 4, 5, 6]:
            start = time()
            try:
                url = 'https://123fans.cn/results.php?qi=%d&c=%d'\
                      % (page_index, class_index)
                req = urllib2.Request(url, None)
                response = urllib2.urlopen(req)
                html_doc = response.read()
                soup = BeautifulSoup(html_doc)
                children = [k for k in soup.children][1]
                lis = children.select('.odd')
                for k in lis:
                    try:
                        name = k.select('.name')[0].string
                        all_person_set.add(name)
                        f_fans.write(name+'\n')
                    except:
                        traceback.print_exc()
                        continue
                print page_index, class_index, \
                    len(all_person_set), time()-start
            except:
                print 'error', page_index, class_index
        sleep(5)
    all_person_set = list(all_person_set)
    msgpack.dump(all_person_set, open('fans.p', 'w'))
开发者ID:ustbliubo2014,项目名称:FaceRecognition,代码行数:30,代码来源:person_crawler.py


示例6: load_check_result_url

def load_check_result_url(dic_file, check_url_file):
    person_result_dic = {}   # {person:([](right_set),[](wrong_set))} # 肯定正确和肯定错的的图片
    right_url_count = wrong_url_count = error_format_count = no_baike_count = no_meaning_count = 0
    if os.path.exists(dic_file):
        person_result_dic = msgpack.load(open(dic_file, 'rb'))
    for line in open(check_url_file):
        tmp = line.rstrip().split('\t')
        # [person_name, pic_index, pic_url, baike_name, baike_sim, newbaike_sim, guess_info]
        person_name = tmp[0]
        right_list, wrong_list = person_result_dic.get(person_name, ([], []))
        if len(tmp) == 7:
            if tmp[3] not in no_meaning_list:
                if tmp[3] == no_find_baike:
                    no_baike_count += 1
                    continue
                else:
                    if get_newbaike_sim(tmp[4]) > sim_threshold:
                        if tmp[0] == tmp[3]:
                            right_list.append(tmp[1])
                            right_url_count += 1
                        else:
                            wrong_url_count += 1
                            wrong_list.append(tmp[1])
                    else:   # 小于某概率时结果不可信,需要标注
                        no_baike_count += 1
                        continue
            else:
                no_meaning_count += 1
                continue
        else:
            error_format_count += 1
            continue
        person_result_dic[person_name] = (right_list, wrong_list)
    print right_url_count, wrong_url_count, no_baike_count, no_meaning_count, error_format_count
    msgpack.dump(person_result_dic, open('person_result_dic.p', 'w'))
开发者ID:ustbliubo2014,项目名称:FaceRecognition,代码行数:35,代码来源:person_pic_arrangement.py


示例7: main

def main():
    dialect_name, working_dir = sys.argv[1:]
    
    executor = sqlexecutor.executor(dialect_name, working_dir)
    
    print "Ready"
    sys.stdout.flush()
    try:
        for message in msgpack.Unpacker(sys.stdin, read_size=1):
            command = message[0]
            args = message[1:]
            
            if command == "execute":
                (creation_sql, query, ) = args
                result = executor.execute(creation_sql, query)
                if result.table is None:
                    column_names = None
                    rows = None
                else:
                    column_names = result.table.column_names
                    rows = result.table.rows
                
                
                msgpack.dump((result.error, column_names, rows), sys.stdout)
                sys.stdout.flush()
            else:
                return
            
    finally:
        executor.close()
开发者ID:mwilliamson,项目名称:sqlexecutor,代码行数:30,代码来源:process.py


示例8: dump

    def dump(data, filepath):
        '''
        Write data as as type self.ext to filepath. json or msgpack
        '''
        if ' ' in filepath:
            raise raeting.KeepError("Invalid filepath '{0}' "
                                    "contains space".format(filepath))

        if hasattr(data, 'get'):
            for key, val in data.items():  # P3 json.dump no encoding parameter
                if isinstance(val, (bytes, bytearray)):
                    data[key] = val.decode('utf-8')

        root, ext = os.path.splitext(filepath)
        if ext == '.json':
            with ocfn(filepath, "w+") as f:
                json.dump(data, f, indent=2)
                f.flush()
                os.fsync(f.fileno())
        elif ext == '.msgpack':
            if not msgpack:
                raise raeting.KeepError("Invalid filepath ext '{0}' "
                            "needs msgpack installed".format(filepath))
            with ocfn(filepath, "w+b", binary=True) as f:
                msgpack.dump(data, f, encoding='utf-8')
                f.flush()
                os.fsync(f.fileno())
        else:
            raise raeting.KeepError("Invalid filepath ext '{0}' "
                        "not '.json' or '.msgpack'".format(filepath))
开发者ID:DSRCompany,项目名称:raet,代码行数:30,代码来源:keeping.py


示例9: get_or_build

def get_or_build(path, build_fn, *args, **kwargs):
    """
    Load from serialized form or build an object, saving the built
    object.

    Remaining arguments are provided to `build_fn`.
    """

    save = False
    obj = None

    if path is not None and os.path.isfile(path):
        with open(path, 'rb') as obj_f:
            obj = msgpack.load(obj_f, use_list=False, encoding='utf-8')
    else:
        save = True

    if obj is None:
        obj = build_fn(*args, **kwargs)

        if save and path is not None:
            with open(path, 'wb') as obj_f:
                msgpack.dump(obj, obj_f)

    return obj
开发者ID:abnering,项目名称:dynamic_cnn_for_nlp,代码行数:25,代码来源:glove.py


示例10: wedge

def wedge(cluster_set, report_cluster_status=False, force_wedge_thrsh=False):
    # The lower bound of the edges being processed by the wedge algorithm.
    global edge_cut_prob
    global wedge_thrsh

    if not force_wedge_thrsh:
        edge_cut_prob = bconfig.WEDGE_THRESHOLD / 4.
        wedge_thrsh = bconfig.WEDGE_THRESHOLD
    else:
        edge_cut_prob = force_wedge_thrsh / 4.
        wedge_thrsh = force_wedge_thrsh

    matr = ProbabilityMatrix(cluster_set.last_name)
    matr.load()

    global h5file
    h5filepath = bconfig.TORTOISE_FILES_PATH+'wedge_cache_'+str(PID())
    h5file = h5py.File(h5filepath)

    convert_cluster_set(cluster_set, matr)
    del matr # be sure that this is the last reference!

    do_wedge(cluster_set)

    report = []
    if bconfig.DEBUG_WEDGE_PRINT_FINAL_CLUSTER_COMPATIBILITIES or report_cluster_status:
        msg = []
        for cl1 in cluster_set.clusters:
            for cl2 in cluster_set.clusters:
                if cl2 > cl1:
                    id1 = cluster_set.clusters.index(cl1)
                    id2 = cluster_set.clusters.index(cl2)
                    c12 = _compare_to(cl1,cl2)
                    c21 = _compare_to(cl2,cl1)
                    report.append((id1,id2,c12+c21))
                    msg.append( ' %s vs %s : %s + %s = %s -- %s' %  (id1, id2, c12, c21, c12+c21, cl1.hates(cl2)))
        msg = 'Wedge final clusters for %s: \n' % str(wedge_thrsh) + '\n'.join(msg)
        if not bconfig.DEBUG_WEDGE_OUTPUT and bconfig.DEBUG_WEDGE_PRINT_FINAL_CLUSTER_COMPATIBILITIES:
            print
            print msg
            print
        wedge_print(msg)


    restore_cluster_set(cluster_set)

    if bconfig.DEBUG_CHECKS:
        assert cluster_set._debug_test_hate_relation()
        assert cluster_set._debug_duplicated_recs()

    if report_cluster_status:
        destfile = '/tmp/baistats/cluster_status_report_pid_%s_lastname_%s_thrsh_%s' % (str(PID()),str(cluster_set.last_name),str(wedge_thrsh))
        f = filehandler.open(destfile, 'w')
        SER.dump([wedge_thrsh,cluster_set.last_name,report,cluster_set.num_all_bibs],f)
        f.close()
    gc.collect()

    h5file.close()
    os.remove(h5filepath)
开发者ID:BessemAamira,项目名称:invenio,代码行数:59,代码来源:bibauthorid_wedge.py


示例11: dump

 def dump(self, outfile):
     """Write a serialized version of the database to filehandle."""
     db_dict = {
         'meta_prints': self.meta_prints,
         'content_prints': self.content_prints,
         'series_id': self.series_id,
     }
     msgpack.dump(db_dict, outfile)
开发者ID:mbr,项目名称:ministryofbackup,代码行数:8,代码来源:__init__.py


示例12: serializeToFile

 def serializeToFile(self, fname, annotations):
     """
     Overwritten to write Msgpack files.
     """
     # TODO make all image filenames relative to the label file
     import msgpack
     f = open(fname, "w")
     msgpack.dump(annotations, f)
开发者ID:mlilien,项目名称:sloth,代码行数:8,代码来源:container.py


示例13: __call__

 def __call__(self):
   if self.filename == None:
     self.filename = msgpackmemoized_basedir + '/' + self.f.__name__ + '.msgpack'
   if path.exists(self.filename):
     return msgpack.load(open(self.filename))
   result = self.f()
   msgpack.dump(result, open(self.filename, 'w'))
   return result
开发者ID:gkovacs,项目名称:creativity_browsing_survey_analysis,代码行数:8,代码来源:msgpackmemoized.py


示例14: dump

    def dump(cls, records, filepath=None):
        """Dump in the same fashion as load."""

        if filepath is None:
            filepath = os.path.join(config['current_snapshot'], 'repos.msgpack')

        with utils.FaultTolerantFile(filepath) as f:
            msgpack.dump(records, f, default=cls._dumper)
开发者ID:simon-weber,项目名称:Predicting-Code-Popularity,代码行数:8,代码来源:models.py


示例15: match_one_file

def match_one_file(midi_filename, embed_fn, hash_fn, msd_embeddings,
                   msd_sequences, msd_feature_paths, msd_ids, output_filename):
    """
    Match one MIDI file to the million song dataset by computing its CQT,
    pruning by matching its embedding, re-pruning by matching its downsampled
    hash sequence, and finally doing DTW on CQTs on the remaining entries.

    Parameters
    ----------
    midi_filename : str
        Path to a MIDI file to match to the MSD
    embed_fn : function
        Function which takes in a CQT and produces a fixed-length embedding
    hash_fn : function
        Function which takes in a CQT and produces a sequence of binary vectors
    msd_embeddings : np.ndarray
        (# MSD entries x embedding dimension) matrix of all embeddings for all
        entries from the MSD
    msd_sequences : list of np.ndarray
        List of binary vector sequences (represented as ints) for all MSD
        entries
    msd_feature_paths : list of str
        Path to feature files (containing CQT) for each MSD entry
    msd_ids : list of str
        MSD ID of each corresponding entry in the above lists
    output_filename : str
        Where to write the results file, which includes the DTW scores for all
        of the non-pruned MSD entries
    """
    # Try to compute a CQT for the MIDI file
    try:
        m = pretty_midi.PrettyMIDI(midi_filename)
    except Exception as e:
        print 'Could not parse {}: {}'.format(
            os.path.split(midi_filename)[1], traceback.format_exc(e))
        return
    try:
        midi_gram = feature_extraction.midi_cqt(m)
    except Exception as e:
        print "Error creating CQT for {}: {}".format(
            os.path.split(midi_filename)[1], traceback.format_exc(e))
        return
    # Skip this file if the MIDI gram is very long, to avoid memory issues
    if midi_gram.shape[0] > MAX_FRAMES:
        return
    # Compute the embedding of the CQT
    midi_embedding = embed_fn(midi_gram.reshape(1, 1, *midi_gram.shape))
    # Compute the hash sequence
    midi_hash_sequence = hash_fn(midi_gram.reshape(1, 1, *midi_gram.shape))
    # Convert to sequence of integers
    midi_hash_sequence = dhs.vectors_to_ints(midi_hash_sequence > 0)
    midi_hash_sequence = midi_hash_sequence.astype(np.uint32)
    matches = match_one_midi(
        midi_gram, midi_embedding, midi_hash_sequence, msd_embeddings,
        msd_sequences, msd_feature_paths, msd_ids)
    # Write out the result
    with open(output_filename, 'wb') as f:
        msgpack.dump(matches, f)
开发者ID:craffel,项目名称:midi-dataset,代码行数:58,代码来源:match.py


示例16: SavePermResults

def SavePermResults(path,name,method,*args):
    data = []
    for thing in enumerate(args):
        data.append(thing)
    if method=='msgpack':
        with open(os.path.join(path,name+'.mpac'),'wb') as f:
            msgpack.dump(data,f)
    else:
        with open(os.path.join(path,name+'.pickle'),'wb') as f:
            pickle.dump(data,f)
开发者ID:mangstad,项目名称:FDR_permutations,代码行数:10,代码来源:slab.py


示例17: make_hanzi_converter

def make_hanzi_converter(table_in, msgpack_out):
    table = {}
    with open(table_in, encoding="utf-8") as infile:
        for line in infile:
            hexcode, char = line.rstrip("\n").split("\t")
            codept = int(hexcode, 16)
            assert len(char) == 1
            if chr(codept) != char:
                table[codept] = char
    with gzip.open(msgpack_out, "wb") as outfile:
        msgpack.dump(table, outfile, encoding="utf-8")
开发者ID:plichten,项目名称:wordfreq,代码行数:11,代码来源:make_chinese_mapping.py


示例18: make_hanzi_converter

def make_hanzi_converter(table_in, msgpack_out):
    table = {}
    with open(table_in, encoding='utf-8') as infile:
        for line in infile:
            hexcode, char = line.rstrip('\n').split('\t')
            codept = int(hexcode, 16)
            assert len(char) == 1
            if chr(codept) != char:
                table[codept] = char
    with gzip.open(msgpack_out, 'wb') as outfile:
        msgpack.dump(table, outfile, raw=False)
开发者ID:LuminosoInsight,项目名称:wordfreq,代码行数:11,代码来源:make_chinese_mapping.py


示例19: create_train_valid_data

def create_train_valid_data(folder='/data/liubo/face/research_feature_self'):
    # 根据已经存在的数据训练人脸验证模型
    person_list = os.listdir(folder)
    path_feature_dic = {}  #
    for person in person_list:
        person_path = os.path.join(folder, person)
        pic_feature_list = os.listdir(person_path)
        for pic_feature_path in pic_feature_list:
            pic_feature_path = os.path.join(person_path, pic_feature_path)
            pic_feature = msgpack_numpy.load(open(pic_feature_path, 'rb'))
            path_feature_dic[pic_feature_path] = pic_feature
    msgpack.dump(path_feature_dic, open('research_feature.p', 'wb'))
开发者ID:ustbliubo2014,项目名称:FaceRecognition,代码行数:12,代码来源:research_model.py


示例20: write_http_response_to_temp_file

def write_http_response_to_temp_file(http_response):
    """
    Write an HTTPResponse instance to a temp file using msgpack

    :param http_response: The HTTP response
    :return: The name of the file
    """
    temp = get_temp_file('http')
    data = http_response.to_dict()
    msgpack.dump(data, temp, use_bin_type=True)
    temp.close()
    return temp.name
开发者ID:andresriancho,项目名称:w3af,代码行数:12,代码来源:serialization.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msgpack.dumps函数代码示例发布时间:2022-05-27
下一篇:
Python msgfmt.make函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap