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


Python pytoml.dumps方法代码示例

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


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

示例1: encode_json

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def encode_json(data, ordered, indent):
    if indent is True:
        indent = 2

    if indent:
        separators = (',', ': ')
    else:
        separators = (',', ':')

    try:
        return json.dumps(
            data,
            default=json_default,
            ensure_ascii=False,
            indent=indent,
            separators=separators,
            sort_keys=not ordered
        ) + "\n"
    except TypeError as e:
        raise ValueError('Cannot convert data to JSON ({0})'.format(e)) 
开发者ID:dbohdan,项目名称:remarshal,代码行数:22,代码来源:remarshal.py

示例2: encode_toml

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def encode_toml(data, ordered):
    try:
        return pytoml.dumps(data, sort_keys=not ordered)
    except AttributeError as e:
        if str(e) == "'list' object has no attribute 'keys'":
            raise ValueError(
                'Cannot convert non-dictionary data to '
                'TOML; use "wrap" to wrap it in a '
                'dictionary'
            )
        else:
            raise e
    except TypeError as e:
        if str(e) == "'in <string>' requires string as left operand, not int":
            raise ValueError('Cannot convert binary to TOML')
        else:
            raise ValueError('Cannot convert data to TOML ({0})'.format(e)) 
开发者ID:dbohdan,项目名称:remarshal,代码行数:19,代码来源:remarshal.py

示例3: __str__

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def __str__(self):
        sanitized = {}
        for k, v in six.iteritems(self.__dict__):
            if isinstance(v, np.ndarray):
                sanitized[k] = v.tolist()
            else:
                sanitized[k] = v
        return toml.dumps(sanitized) 
开发者ID:aschampion,项目名称:diluvian,代码行数:10,代码来源:config.py

示例4: write

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def write(self, party):
        #print(toml.dumps(party))
        with open(self.filename, 'w') as fout:
            toml.dump(party, fout) 
开发者ID:mpirnat,项目名称:dndme,代码行数:6,代码来源:writers.py

示例5: parametersToTOML

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def parametersToTOML(Settings):
    Text = pytoml.dumps(Settings)
    
    return Text 
开发者ID:Gab0,项目名称:japonicus,代码行数:6,代码来源:TOMLutils.py

示例6: encode_cbor

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def encode_cbor(data):
    try:
        return cbor2.dumps(data)
    except cbor2.EncoderError as e:
        raise ValueError('Cannot convert data to CBOR ({0})'.format(e)) 
开发者ID:dbohdan,项目名称:remarshal,代码行数:7,代码来源:remarshal.py

示例7: initialise

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def initialise(self):
        if (self.directory / 'pyproject.toml').exists():
            resp = input("pyproject.toml exists - overwrite it? [y/N]: ")
            if (not resp) or resp[0].lower() != 'y':
                return

        module = self.prompt_text('Module name', self.guess_module_name(),
                                  str.isidentifier)
        author = self.prompt_text('Author', self.defaults.get('author'),
                                  lambda s: s != '')
        author_email = self.prompt_text('Author email',
                        self.defaults.get('author_email'), self.validate_email)
        if 'home_page_template' in self.defaults:
            home_page_default = self.defaults['home_page_template'].replace(
                                                        '{modulename}', module)
        else:
            home_page_default = None
        home_page = self.prompt_text('Home page', home_page_default, self.validate_homepage,
                                     retry_msg="Should start with http:// or https:// - try again.")
        license = self.prompt_options('Choose a license (see http://choosealicense.com/ for more info)',
                    license_choices, self.defaults.get('license'))

        self.update_defaults(author=author, author_email=author_email,
                             home_page=home_page, module=module, license=license)

        metadata = OrderedDict([
            ('module', module),
            ('author', author),
            ('author-email', author_email),
        ])
        if home_page:
            metadata['home-page'] = home_page
        if license != 'skip':
            metadata['classifiers'] = [license_names_to_classifiers[license]]
            self.write_license(license, author)

        with (self.directory / 'pyproject.toml').open('w', encoding='utf-8') as f:
            f.write(TEMPLATE.format(metadata=toml.dumps(metadata)))

        print()
        print("Written pyproject.toml; edit that file to add optional extra info.") 
开发者ID:holzschu,项目名称:Carnets,代码行数:43,代码来源:init.py

示例8: fill_volumes_with_model

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def fill_volumes_with_model(
        model_file,
        volumes,
        filename,
        resume_filename=None,
        partition=False,
        viewer=False,
        **kwargs):
    if '{volume}' not in filename:
        raise ValueError('HDF5 filename must contain "{volume}" for volume name replacement.')
    if resume_filename is not None and '{volume}' not in resume_filename:
        raise ValueError('TOML resume filename must contain "{volume}" for volume name replacement.')

    if partition:
        _, volumes = partition_volumes(volumes)

    for volume_name, volume in six.iteritems(volumes):
        logging.info('Filling volume %s...', volume_name)
        volume = volume.downsample(CONFIG.volume.resolution)
        if resume_filename is not None:
            resume_volume_filename = resume_filename.format(volume=volume_name)
            resume_volume = six.next(six.itervalues(HDF5Volume.from_toml(resume_volume_filename)))
            resume_prediction = resume_volume.to_memory_volume().label_data
        else:
            resume_prediction = None

        volume_filename = filename.format(volume=volume_name)
        checkpoint_filename = volume_filename + '_checkpoint'
        prediction, conflict_count = fill_volume_with_model(
                model_file,
                volume,
                resume_prediction=resume_prediction,
                checkpoint_filename=checkpoint_filename,
                **kwargs)

        config = HDF5Volume.write_file(
                volume_filename + '.hdf5',
                CONFIG.volume.resolution,
                label_data=prediction)
        config['name'] = volume_name + ' segmentation'
        with open(volume_filename + '.toml', 'wb') as tomlfile:
            tomlfile.write('# Filling model: {}\n'.format(model_file))
            tomlfile.write('# Filling kwargs: {}\n'.format(str(kwargs)))
            tomlfile.write(str(toml.dumps({'dataset': [config]})))

        if viewer:
            viewer = WrappedViewer(voxel_size=list(np.flipud(CONFIG.volume.resolution)))
            subvolume = volume.get_subvolume(SubvolumeBounds(start=np.zeros(3, dtype=np.int64), stop=volume.shape))
            viewer.add(subvolume.image, name='Image')
            viewer.add(prediction, name='Labels')
            viewer.add(conflict_count, name='Conflicts')

            viewer.print_view_prompt() 
开发者ID:aschampion,项目名称:diluvian,代码行数:55,代码来源:diluvian.py

示例9: convert

# 需要导入模块: import pytoml [as 别名]
# 或者: from pytoml import dumps [as 别名]
def convert(path):
    cp = configparser.ConfigParser()
    with path.open(encoding='utf-8') as f:
        cp.read_file(f)

    ep_file = Path('entry_points.txt')
    metadata = OrderedDict()
    for name, value in cp['metadata'].items():
        if name in metadata_list_fields:
            metadata[name] = [l for l in value.splitlines() if l.strip()]
        elif name == 'entry-points-file':
            ep_file = Path(value)
        else:
            metadata[name] = value

    if 'scripts' in cp:
        scripts = OrderedDict(cp['scripts'])
    else:
        scripts = {}

    entrypoints = CaseSensitiveConfigParser()
    if ep_file.is_file():
        with ep_file.open(encoding='utf-8') as f:
            entrypoints.read_file(f)

    written_entrypoints = False
    with Path('pyproject.toml').open('w', encoding='utf-8') as f:
        f.write(TEMPLATE.format(metadata=pytoml.dumps(metadata)))

        if scripts:
            f.write('\n[tool.flit.scripts]\n')
            pytoml.dump(scripts, f)

        for groupname, group in entrypoints.items():
            if not dict(group):
                continue

            if '.' in groupname:
                groupname = '"{}"'.format(groupname)
            f.write('\n[tool.flit.entrypoints.{}]\n'.format(groupname))
            pytoml.dump(OrderedDict(group), f)
            written_entrypoints = True

    print("Written 'pyproject.toml'")
    files = str(path)
    if written_entrypoints:
        files += ' and ' + str(ep_file)
    print("Please check the new file, then remove", files) 
开发者ID:holzschu,项目名称:Carnets,代码行数:50,代码来源:tomlify.py


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