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

Python utilities.write_file函数代码示例

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

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



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

示例1: generate_training_set

def generate_training_set(follow, followed, ratio, solution_file, data_file):
    """ Uses the solution file to generate training set to train
    the model, hoping this method can get better result.
    Ratio controls the fraction of pos and neg data sets, if ratio is -1,
    the fraction is the origion fraction."""

    raw_solution = utilities.read_file(solution_file, False)
    dict_solution = {}
    for i in range(len(raw_solution)):
        row = raw_solution[i]
        dict_solution[int(row[0])] = set(int(n) for n in row[1 : :])

    x_train = [['spring brother is a true man']]
    for node in dict_solution.keys():
        nodes_pos = dict_solution[node]
        for n in nodes_pos:
            features = rank.get_features(follow, followed, node, n)
            x_train.append([1] + features)

        nodes_neg = candidate.get_candidates(follow, followed, node)
        nodes_neg.difference_update(nodes_pos)
        nodes_neg = list(nodes_neg)
        perm = random.permutation(len(nodes_neg))
        if ratio != -1:
            num = min(int(len(nodes_pos) * ratio), len(nodes_neg))
        else:
            num = len(nodes_neg)
        for i in range(num):
            node = nodes_neg[perm[i]]
            features = rank.get_features(follow, followed, node, n)
            x_train.append([0] + features)

    utilities.write_file(data_file, x_train)
开发者ID:FindBoat,项目名称:Kaggle,代码行数:33,代码来源:validation.py


示例2: compile_and_write

 def compile_and_write(self, idl_filename):
     interface_name = idl_filename_to_interface_name(idl_filename)
     definitions = self.reader.read_idl_definitions(idl_filename)
     output_code_list = self.code_generator.generate_code(
         definitions, interface_name)
     for output_path, output_code in output_code_list:
         write_file(output_code, output_path, self.only_if_changed)
开发者ID:PavelMovchan,项目名称:crosswalk-android-extensions,代码行数:7,代码来源:idl_compiler.py


示例3: main

def main():
    # Check input
    if len(sys.argv) != 5:
        print"usage: python run_ML_FW.py [train file] [setting file] [model folder] [test data folder]"
        exit()
    # Get environment variables
    train_file = sys.argv[1]
    setting_file = sys.argv[2]
    model_folder = sys.argv[3]
    test_data_folder = sys.argv[4]
    tops = 10#int(sys.argv[5])    
    # Create model folder if it doesn't exist
    if os.path.exists(model_folder):
        shutil.rmtree(model_folder)
    os.makedirs(model_folder)
    # Read settings
    print'reading setting ...'
    ddict = utilities.read_setting(setting_file)
    print'write setting ...'
    file_name = '%s/setting.txt'%(model_folder)
    utilities.write_setting(ddict, file_name)
    # Read data for computing perplexities
    print'read data for computing perplexities ...'
    (wordids_1, wordcts_1, wordids_2, wordcts_2) = \
    utilities.read_data_for_perpl(test_data_folder)
    # Initialize the algorithm
    print'initialize the algorithm ...'
    ml_fw = ML_FW.MLFW(ddict['num_terms'], ddict['num_topics'], ddict['tau0'], ddict['kappa'], ddict['iter_infer'])
    # Start
    print'start!!!'
    i = 0
    while i < ddict['iter_train']:
        i += 1
        print'\n***iter_train:%d***\n'%(i)
        datafp = open(train_file, 'r')
        j = 0
        while True:
            j += 1
            (wordids, wordcts) = utilities.read_minibatch_list_frequencies(datafp, ddict['batch_size'])
            # Stop condition
            if len(wordids) == 0:
                break
            # 
            print'---num_minibatch:%d---'%(j)
            (time_e, time_m, theta) = ml_fw.static_online(ddict['batch_size'], wordids, wordcts)
            # Compute sparsity
            sparsity = utilities.compute_sparsity(theta, theta.shape[0], theta.shape[1], 't')
            # Compute perplexities
            LD2 = utilities.compute_perplexities_fw(ml_fw.beta, ddict['iter_infer'], \
                               wordids_1, wordcts_1, wordids_2, wordcts_2)
            # Search top words of each topics
            list_tops = utilities.list_top(ml_fw.beta, tops)
            # Write files
            utilities.write_file(i, j, ml_fw.beta, time_e, time_m, theta, sparsity, LD2, list_tops, tops, model_folder)
        datafp.close()
    # Write final model to file
    file_name = '%s/beta_final.dat'%(model_folder)
    utilities.write_topics(ml_fw.beta, file_name)
    # Finish
    print'done!!!'        
开发者ID:cuongnb,项目名称:OPE,代码行数:60,代码来源:run_ML_FW.py


示例4: write_event_interfaces_file

def write_event_interfaces_file(event_idl_files, destination_filename, only_if_changed):
    def extended_attribute_string(name, value):
        if name == 'RuntimeEnabled':
            value += 'Enabled'
        return name + '=' + value

    def interface_line(full_path):
        relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, source_dir))
        relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)

        idl_file_contents = get_file_contents(full_path)
        extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents)
        extended_attributes_list = [
            extended_attribute_string(name, extended_attributes[name])
            for name in EXPORTED_EXTENDED_ATTRIBUTES
            if name in extended_attributes]

        return '%s %s\n' % (relative_path_posix,
                            ', '.join(extended_attributes_list))

    lines = ['namespace="Event"\n',
             '\n']
    interface_lines = [interface_line(event_idl_file)
                       for event_idl_file in event_idl_files]
    interface_lines.sort()
    lines.extend(interface_lines)
    write_file(''.join(lines), destination_filename, only_if_changed)
开发者ID:coinpayee,项目名称:blink,代码行数:27,代码来源:generate_event_interfaces.py


示例5: generate_callback_function_impl

 def generate_callback_function_impl(output_directory, component):
     generator = CodeGeneratorCallbackFunction(
         component_info_providers[component], cache_dir=None,
         output_dir=output_directory, target_component=component)
     outputs = generator.generate_code()
     for output_path, output_code in outputs:
         write_file(output_code, output_path)
开发者ID:ollie314,项目名称:chromium,代码行数:7,代码来源:bindings_tests.py


示例6: generate_union_type_containers

 def generate_union_type_containers(output_directory, component):
     generator = CodeGeneratorUnionType(
         component_info_providers[component], cache_dir=None,
         output_dir=output_directory, target_component=component)
     outputs = generator.generate_code()
     for output_path, output_code in outputs:
         write_file(output_code, output_path)
开发者ID:ollie314,项目名称:chromium,代码行数:7,代码来源:bindings_tests.py


示例7: generate_conditional_features

def generate_conditional_features(info_provider, options, idl_filenames):
    reader = IdlReader(info_provider.interfaces_info, options.cache_directory)
    jinja_env = initialize_jinja_env(options.cache_directory)

    # Extract the bidirectional mapping of conditional features <-> interfaces
    # from the global info provider and the supplied list of IDL files.
    feature_info = conditional_features_info(info_provider,
                                             reader, idl_filenames,
                                             options.target_component.lower())

    # Convert that mapping into the context required for the Jinja2 templates.
    template_context = conditional_features_context(
        MODULE_PYNAME, feature_info)

    # Generate and write out the header file
    header_text = render_template(jinja_env.get_template(
        "ConditionalFeaturesFor%s.h.tmpl" % options.target_component.title()), template_context)
    header_path = posixpath.join(options.output_directory,
                                 "ConditionalFeaturesFor%s.h" % options.target_component.title())
    write_file(header_text, header_path)

    # Generate and write out the implementation file
    cpp_text = render_template(jinja_env.get_template(
        "ConditionalFeaturesFor%s.cpp.tmpl" % options.target_component.title()), template_context)
    cpp_path = posixpath.join(options.output_directory,
                              "ConditionalFeaturesFor%s.cpp" % options.target_component.title())
    write_file(cpp_text, cpp_path)
开发者ID:eval1749,项目名称:evita,代码行数:27,代码来源:generate_conditional_features.py


示例8: compile_and_write

 def compile_and_write(self, idl_filename):
     interface_name = idl_filename_to_interface_name(idl_filename)
     definitions = self.reader.read_idl_definitions(idl_filename)
     target_definitions = definitions[self.target_component]
     output_code_list = self.code_generator.generate_code(
         target_definitions, interface_name)
     for output_path, output_code in output_code_list:
         write_file(output_code, output_path)
开发者ID:mirror,项目名称:chromium,代码行数:8,代码来源:idl_compiler.py


示例9: _save_previous_version

 def _save_previous_version(self):
     """
     Save current installed mysql version to cache file.
     It will be previous version after new installation.
     """
     version = mysql_version()
     if version:
         write_file(self.CACHE_VERSION_FILE, version)
开发者ID:cloudlinuxadmin,项目名称:mysql-governor,代码行数:8,代码来源:base.py


示例10: compile_file

    def compile_file(self, idl_filename):
        definitions = self.reader.read_idl_definitions(idl_filename)

        files = self.code_generator.generate_code(definitions)

        for file_data in files:
            file_name = os.path.join(self.output_directory,
                                     file_data['file_name'])
            write_file(file_data['contents'], file_name)
开发者ID:eval1749,项目名称:evita,代码行数:9,代码来源:idl_to_js_externs.py


示例11: write_global_constructors_partial_interface

def write_global_constructors_partial_interface(interface_name, destination_filename, constructor_attributes_list, only_if_changed):
    # FIXME: replace this with a simple Jinja template
    lines = (['[\n'] +
             ['    NoHeader,\n'] +
             [']\n'] +
             ['partial interface %s {\n' % interface_name] +
             ['    %s;\n' % constructor_attribute
              # FIXME: sort by interface name (not first by extended attributes)
              for constructor_attribute in sorted(constructor_attributes_list)] +
             ['};\n'])
    write_file(''.join(lines), destination_filename, only_if_changed)
开发者ID:Mihiri,项目名称:blink,代码行数:11,代码来源:generate_global_constructors.py


示例12: write_global_constructors_partial_interface

def write_global_constructors_partial_interface(interface_name, idl_filename, constructor_attributes_list):
    # FIXME: replace this with a simple Jinja template
    lines = (['partial interface %s {\n' % interface_name] +
             ['    %s;\n' % constructor_attribute
              # FIXME: sort by interface name (not first by extended attributes)
              for constructor_attribute in sorted(constructor_attributes_list)] +
             ['};\n'])
    write_file(''.join(lines), idl_filename)
    header_filename = os.path.splitext(idl_filename)[0] + '.h'
    idl_basename = os.path.basename(idl_filename)
    write_file(HEADER_FORMAT.format(idl_basename=idl_basename), header_filename)
开发者ID:mirror,项目名称:chromium,代码行数:11,代码来源:generate_global_constructors.py


示例13: compile_and_write

    def compile_and_write(self, idl_filename, output_filenames):
        interface_name = idl_filename_to_interface_name(idl_filename)
        idl_pickle_filename = os.path.join(self.output_directory,
                                           '%s_globals.pickle' % interface_name)
        definitions = self.reader.read_idl_definitions(idl_filename)
        output_code_list = self.code_generator.generate_code(definitions,
                                                             interface_name,
                                                             idl_pickle_filename,
                                                             self.only_if_changed)

        for output_code, output_filename in zip(output_code_list, output_filenames):
            write_file(output_code, output_filename, self.only_if_changed)
开发者ID:Jamesducque,项目名称:mojo,代码行数:12,代码来源:dart_compiler.py


示例14: set_mysql_version

    def set_mysql_version(self, version):
        """
        Set new mysql version for next install
        """
        # check available versions
        versions = ["auto"] + self.REPO_NAMES.keys()
        if version not in versions:
            print >> sys.stderr, "Invalid mysql version."
            print >> sys.stderr, "Available versions: %s" % ", ".join(versions)
            sys.exit(2)

        write_file(self.NEW_VERSION_FILE, version)
开发者ID:cloudlinuxadmin,项目名称:mysql-governor,代码行数:12,代码来源:base.py


示例15: main

def main():
    opts, _ = parse_args()
    # TODO(peria): get rid of |info_provider|
    info_provider = create_component_info_provider(
        opts.info_dir, opts.target_component)
    generator = ExternalReferenceTableGenerator(opts, info_provider)

    idl_files = utilities.read_idl_files_list_from_file(opts.idl_files_list, False)
    for idl_file in idl_files:
        generator.process_idl_file(idl_file)
    output_code = generator.generate()
    output_path = opts.output
    write_file(output_code, output_path)
开发者ID:eval1749,项目名称:evita,代码行数:13,代码来源:generate_v8_context_snapshot_external_references.py


示例16: generate_test_set

def generate_test_set(follow, followed, test_file, validation_file,
    solution_file, num,  max_remove_num):
    """ Generates the test set for analysis. """

    nodes_exclude = utilities.read_nodes_list(test_file)

    print 'Generating test nodes...'
    nodes_test = generate_test_nodes(follow, nodes_exclude, num)
    writable_nodes_test = [[n] for n in nodes_test]
    solution = generate_solution(follow, followed, nodes_test, max_remove_num)

    utilities.write_file(validation_file, writable_nodes_test)
    utilities.write_file(solution_file, solution)
开发者ID:FindBoat,项目名称:Kaggle,代码行数:13,代码来源:validation.py


示例17: generate_union_type_containers

def generate_union_type_containers(options):
    info_provider = create_component_info_provider(
        options.info_dir, options.target_component)
    if not info_provider.interfaces_info:
        raise Exception('Interfaces info is required to generate '
                        'union types containers')
    generator = CodeGeneratorUnionType(
        info_provider,
        options.cache_directory,
        options.output_directory,
        options.target_component)
    output_code_list = generator.generate_code()
    for output_path, output_code in output_code_list:
        write_file(output_code, output_path, options.write_file_only_if_changed)
开发者ID:dreifachstein,项目名称:chromium-src,代码行数:14,代码来源:idl_compiler.py


示例18: generate_union_type_containers

def generate_union_type_containers(options):
    if not (options.interfaces_info_file and options.component_info_file):
        raise Exception('Interfaces info is required to generate '
                        'union types containers')
    with open(options.interfaces_info_file) as interfaces_info_file:
        interfaces_info = pickle.load(interfaces_info_file)
    with open(options.component_info_file) as component_info_file:
        component_info = pickle.load(component_info_file)
    generator = CodeGeneratorUnionType(
        interfaces_info,
        options.cache_directory,
        options.output_directory,
        options.target_component)
    output_code_list = generator.generate_code(component_info['union_types'])
    for output_path, output_code in output_code_list:
        write_file(output_code, output_path, options.write_file_only_if_changed)
开发者ID:syncfusion,项目名称:SfQtWebKit,代码行数:16,代码来源:idl_compiler.py


示例19: _get_mysqlup

 def _get_mysqlup():
     """
     ? Set value for panel update MYSQLUP option
     """
     if os.path.exists("/etc/cpupdate.conf"):
         shutil.copy2("/etc/cpupdate.conf", "/etc/cpupdate.conf.governor")
         is_mysqlup = grep("/etc/cpupdate.conf", "MYSQLUP")
         if is_mysqlup:
             if not grep(is_mysqlup, "never$", True):
                 replace_lines("/etc/cpupdate.conf", "".join(is_mysqlup),
                               "MYSQLUP=never")
         else:
             add_line("/etc/cpupdate.conf", "\nMYSQLUP=never\n")
     else:
         write_file("/etc/cpupdate.conf.governor", "")
         write_file("/etc/cpupdate.conf", "MYSQLUP=never\n")
开发者ID:cloudlinuxadmin,项目名称:mysql-governor,代码行数:16,代码来源:cpanel.py


示例20: write_event_interfaces_file

def write_event_interfaces_file(event_idl_files, destination_filename, suffix):
    def interface_line(full_path):
        relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, source_dir))
        relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)

        idl_file_contents = get_file_contents(full_path)
        extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents)
        extended_attributes_list = [
            (name, extended_attributes[name])
            for name in EXPORTED_EXTENDED_ATTRIBUTES
            if name in extended_attributes]

        return (relative_path_posix, extended_attributes_list)

    lines = [
        '{',
        'metadata: {',
        '  namespace: "Event",'
    ]
    if suffix:
        lines.append('  suffix: "' + suffix + '",')
        lines.append('  export: "%s_EXPORT",' % suffix.upper())
    else:
        lines.append('  export: "CORE_EXPORT",')
    lines.extend([
        '},',
        'data: ['
    ])
    interface_lines = [interface_line(event_idl_file)
                       for event_idl_file in event_idl_files]
    interface_lines.sort()
    for name, attributes in interface_lines:
        lines.extend([
            '  {',
            '    name: "%s",' % name
        ])
        for param, value in attributes:
            if param == 'RuntimeEnabled':
                value += 'Enabled'
            lines.append('    %s: "%s",' % (param, value))
        lines.append('  },')
    lines.extend([
        ']',
        '}'
    ])
    write_file('\n'.join(lines), destination_filename)
开发者ID:eval1749,项目名称:evita,代码行数:46,代码来源:generate_event_interfaces.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utilities.write_keywords函数代码示例发布时间:2022-05-26
下一篇:
Python utilities.writeShape函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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