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


Python Formatter.format方法代码示例

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


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

示例1: generate

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
    def generate(self, save=True):
        "Generates photo file in current format"
        crop_box = None
        if self.crop_left:
            crop_box = (self.crop_left, self.crop_top, \
                    self.crop_left + self.crop_width, self.crop_top + self.crop_height)

        important_box = None
        if self.photo.important_top is not None:
            p = self.photo
            important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)

        formatter = Formatter(Image.open(self.photo.image.path), self.format, crop_box=crop_box, important_box=important_box)

        stretched_photo, crop_box = formatter.format()

        self.crop_left, self.crop_top, right, bottom = crop_box
        self.crop_width = right - self.crop_left
        self.crop_height = bottom - self.crop_top

        self.width, self.height = stretched_photo.size
        stretched_photo.save(self.file(), quality=self.format.resample_quality)

        f = open(self.file())
        file = ContentFile(f.read())
        f.close()

        self.image.save(self.file(relative=True), file, save)
开发者ID:chewable,项目名称:ella,代码行数:30,代码来源:models.py

示例2: _generate_img

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
    def _generate_img(self):
        crop_box = None
        if self.crop_left:
            crop_box = (self.crop_left, self.crop_top, \
                    self.crop_left + self.crop_width, self.crop_top + self.crop_height)

        important_box = None
        if self.photo.important_top is not None:
            p = self.photo
            important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)

        formatter = Formatter(self.photo._get_image(), self.format, crop_box=crop_box, important_box=important_box)

        return formatter.format()
开发者ID:andymccurdy,项目名称:ella,代码行数:16,代码来源:models.py

示例3: generate

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
    def generate(self):
        "Generates photo file in current format"
        crop_box = None
        if self.crop_left:
            crop_box = (self.crop_left, self.crop_top, \
                    self.crop_left + self.crop_width, self.crop_top + self.crop_height)

        important_box = None
        if self.photo.important_top:
            p = self.photo
            important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)

        formatter = Formatter(Image.open(self.filename), self.format, crop_box=crop_box, important_box=important_box)

        stretched_photo, crop_box = formatter.format()
        self.width, self.height = stretched_photo.size
        self.filename = self.file(relative=True)
        stretched_photo.save(self.file(), quality=self.format.resample_quality)
开发者ID:dedaluz,项目名称:ella,代码行数:20,代码来源:models.py

示例4: __init__

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
class Cli:
    def __init__(self, module_name, config, parser):
        self.__parser = parser
        self.formatter = Formatter(module_name)
        self.__option_parser = self.__get_option_parser(config, parser)

        self.formatter.option_parser = self.__option_parser

    def parse_args(self):
        return self.__option_parser.parse_args()

    def __get_option_parser(self, config, parser):
        option_parser = OptionParser(self.formatter.format(config.usage))

        self.__add_options(config, parser, option_parser)
        self.__add_option_groups(config, option_parser, parser)

        return option_parser

    def __add_options(self, group, parser, option_parser):
        for option in group.options:
            self.__add_option(parser, option, option_parser)

    def __add_option(self, parser, option, option_parser):
        kwargs = self.__get_option_kwargs(parser, option.kwargs)
        option_parser.add_option(*option.argv, **kwargs)

    def __get_option_kwargs(self, parser, kwargs):
        if "callback" in kwargs:
            kwargs["callback"] = getattr(parser, kwargs["callback"])

        return kwargs

    def __add_option_groups(self, config, option_parser, parser):
        for group in config.groups:
            self.__add_option_group(option_parser, group, parser)

    def __add_option_group(self, option_parser, group, parser):
        option_parser_group = OptionGroup(option_parser, group.title, group.description)
        self.__add_options(group, parser, option_parser_group)
        option_parser.add_option_group(option_parser_group)
开发者ID:chris-lock,项目名称:msvg,代码行数:43,代码来源:cli.py

示例5: _generate_img

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
    def _generate_img(self):
        crop_box = None
        if self.crop_left:
            crop_box = (self.crop_left, self.crop_top, \
                    self.crop_left + self.crop_width, self.crop_top + self.crop_height)

        important_box = None
        if self.photo.important_top is not None:
            p = self.photo
            important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)

        image = None
        if crop_box is None and self.format.master_id:
            try:
                fp = FormatedPhoto.objects.get(format=self.format.master_id, photo=self.photo)
                image = Image.open(fp.image)
            except FormatedPhoto.DoesNotExist:
                pass

        if image is None:
            image = self.photo._get_image()
        formatter = Formatter(image, self.format, crop_box=crop_box, important_box=important_box)

        return formatter.format()
开发者ID:fragaria,项目名称:ella,代码行数:26,代码来源:models.py

示例6: Formatter

# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
#!/usr/bin/env python

from info import InstanceInfo
from formatter import Formatter

f = Formatter()
i = InstanceInfo(
    name="some_instance",
    virt_name="instance-0000043c",
    id=1084,
    uuid="35315889-d4f1-4067-b14e-34b5e4bd49c8",
    fixed_ip="x.x.x.x",
    host="novacpu03.foo.bar.baz",
    tenant="Something",
    vm_state="active",
    task_state=None,
    vcpus=8,
    ram="16.0GB",
    snapshots=["6d0fd729-7034-41bb-b006-c98a2f39b275",
               "3acc483b-0f2f-4c73-9854-3f4b2482bee6"])

i['something'] = [1,2,3,4,5]

print(f.format([i]))
开发者ID:JCallicoat,项目名称:pulsar-ng,代码行数:26,代码来源:__init__.py


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