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

Python textwrap.indent函数代码示例

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

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



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

示例1: print_scrape_results_http

def print_scrape_results_http(results):
    """Print the results obtained by "http" method.

    Args:
        results: The results to be printed to stdout.
    """
    for t in results:
        for result in t:
            logger.info('{} links found. The search with the keyword "{}" yielded the result: "{}"'.format(
                len(result['results']), result['search_keyword'], result['num_results_for_kw']))
            import textwrap
            for result_set in ('results', 'ads_main', 'ads_aside'):
                if result_set in result.keys():
                    print('### {} link results for "{}" ###'.format(len(result[result_set]), result_set))
                    for link_title, link_snippet, link_url, link_position in result[result_set]:
                        try:
                            print('  Link: {}'.format(unquote(link_url.geturl())))
                        except AttributeError as ae:
                            print(ae)
                        if Config['GLOBAL'].getint('verbosity') > 1:
                            print(
                                '  Title: \n{}'.format(textwrap.indent('\n'.join(textwrap.wrap(link_title, 50)), '\t')))
                            print(
                                '  Description: \n{}\n'.format(
                                    textwrap.indent('\n'.join(textwrap.wrap(link_snippet, 70)), '\t')))
                            print('*' * 70)
                            print()
开发者ID:vgoklani,项目名称:GoogleScraper,代码行数:27,代码来源:core.py


示例2: check_negative

def check_negative(dirname, results, expected):
    """Checks the results with the expected results."""

    inputs  = (set(results['inputs']),  set(expected['!inputs']))
    outputs = (set(results['outputs']), set(expected['!outputs']))

    if not inputs[1].isdisjoint(inputs[0]):
        print(bcolors.ERROR + ': Found inputs that should not exist:')
        s = pprint.pformat(inputs[1] & inputs[1], width=1)
        print(textwrap.indent(s, '       '))
        return False

    if not outputs[1].isdisjoint(outputs[0]):
        print(bcolors.ERROR + ': Found outputs that should not exist:')
        s = pprint.pformat(outputs[1] & outputs[1], width=1)
        print(textwrap.indent(s, '       '))
        return False

    existing = [p for p in (os.path.join(dirname, p) for p in outputs[1])
                if os.path.exists(p)]

    if existing:
        print(bcolors.ERROR + ': Outputs exist on from file system, but should not:')
        pprint.pprint(existing)
        return False

    return True
开发者ID:jasonwhite,项目名称:button-deps,代码行数:27,代码来源:test.py


示例3: write_options_group

    def write_options_group(self, write, group):
        def is_positional_group(group):
            return any(not o.option_strings for o in group._group_actions)

        if is_positional_group(group):
            for option in group._group_actions:
                write(option.metavar)
                write(textwrap.indent(option.help or '', ' ' * 4))
            return

        opts = OrderedDict()

        for option in group._group_actions:
            if option.metavar:
                option_fmt = '%s ' + option.metavar
            else:
                option_fmt = '%s'
            option_str = ', '.join(option_fmt % s for s in option.option_strings)
            option_desc = textwrap.dedent((option.help or '') % option.__dict__)
            opts[option_str] = textwrap.indent(option_desc, ' ' * 4)

        padding = len(max(opts)) + 1

        for option, desc in opts.items():
            write(option.ljust(padding), desc)
开发者ID:ThomasWaldmann,项目名称:borg,代码行数:25,代码来源:setup_docs.py


示例4: pretty_print

	def pretty_print(self,m=True,f=False):
		#Print the files and folders under root, with their memory usage if m(with_memory)=True
		#Only print folders is f(folders_only)=True
		base=3
		width=self.depth*base+50
		DFS=[self.root]
		while DFS:
			cur_node=DFS.pop()
			indent_size=cur_node.dist*base
			name=os.path.basename(cur_node.name)
			star_size=width-indent_size-len(name)
			try:
				if m:
					print(textwrap.indent(name,''.join([' ']*indent_size)),''.join(['.']*star_size),cur_node.memsize)
				else:
					print(textwrap.indent(name,''.join([' ']*indent_size)))
			except UnicodeEncodeError as err:
				logging.debug(err)
			for k in cur_node.kiddir:
				DFS.append(k)
			if not f:
				for k in cur_node.kidfile:
					indent_size=k.dist*base
					name=os.path.basename(k.name)
					star_size=width-indent_size-len(name)
					try:
						if m:
							print(textwrap.indent(name,''.join([' ']*indent_size)),''.join(['.']*star_size),k.memsize)
						else:
							print(textwrap.indent(name,''.join([' ']*indent_size)))
					except UnicodeEncodeError as err:
						print ('Handling unicode encode error',err)
开发者ID:JunyiJ,项目名称:Memory_summary_and_file_search,代码行数:32,代码来源:Memory_Tree.py


示例5: play

   def play(self):
      selection = None
      current_sleep = self.start
      current_round = 0

      while True:
         selection = choice_unduplicated(available_notes, selection)
         octave, note = selection.split('.')

         flute = getFlute(notes[selection])
         figlet_note = figlet('{}  {}'.format(octave, note))

         header = ' Interval: {:.2f} | Sleep: {:.2f} | Round {:d}/{:d}'.format(
            self.step, current_sleep, current_round, self.rounds)

         flute_padded = indent(flute, ' ' * 14)
         figlet_width = len(max(figlet_note.splitlines(), key=len))
         note_padded = indent(figlet_note, ' ' * (17 - int(figlet_width/2)))

         system('clear')
         print(header, "\n\n", note_padded, flute_padded, sep='')

         sleep(current_sleep)

         current_round += 1

         if (current_round >= self.rounds):
            current_round = 0
            current_sleep -= self.step

         if (current_sleep <= self.stop):
            break
开发者ID:braph,项目名称:learning2flute,代码行数:32,代码来源:learning2flute.py


示例6: check_positive

def check_positive(dirname, results, expected):
    """Checks the results with the expected results."""

    inputs  = (set(results['inputs']),  set(expected['inputs']))
    outputs = (set(results['outputs']), set(expected['outputs']))

    if not inputs[1].issubset(inputs[0]):
        print(bcolors.ERROR + ': Expected inputs are not a subset of the results.')
        print('       The following were not found in the results:')
        s = pprint.pformat(inputs[1] - inputs[0], width=1)
        print(textwrap.indent(s, '       '))
        print('       Instead, these were found:')
        s = pprint.pformat(inputs[0], width=1)
        print(textwrap.indent(s, '       '))
        return False

    if not outputs[1].issubset(outputs[0]):
        print(bcolors.ERROR + ': Expected outputs are not a subset of the results')
        print('       The following were not found in the results:')
        s = pprint.pformat(outputs[1] - outputs[0], width=1)
        print(textwrap.indent(s, '       '))
        print('       Instead, these were found:')
        s = pprint.pformat(outputs[0], width=1)
        print(textwrap.indent(s, '       '))
        return False

    missing = [p for p in (os.path.join(dirname, p) for p in outputs[0])
                if not os.path.exists(p)]

    if missing:
        print(bcolors.ERROR + ': Result outputs missing from file system:')
        pprint.pprint(missing)
        return False

    return True
开发者ID:jasonwhite,项目名称:button-deps,代码行数:35,代码来源:test.py


示例7: training_desc

def training_desc(info, verbosity, precision):
    """
    Textifies a single training history record. Returns a list of lines.
    """
    desc = [
        "Date: {}".format(date_desc(info['date'])),
        "Bot: {bot}".format(**info) +
                ", Trainer: {trainer} {config}".format(**info),
        "Dists: {}".format(indent(dists_desc(info['dists']), " " * 7).strip()),
        "Seeds: {}".format(seeds_desc(info['seeds'], verbosity)),
        "Level: {}".format(level_desc(info['level'])) +
                ", Runs: {}".format(info['runs']) +
                ", Time: {}".format(time_desc(info['time'], precision)),
        "Output: {output}, PRNGs: {prngs_seed}".format(**info) +
                ", Scores: {}".format(scores_desc(info['scores'], verbosity,
                                                  precision))
    ]
    if info['phases'] is not None:
        desc.insert(3, "Phases: {}".format(
                                    phases_desc(info['phases'], precision)))
    if info['emphases']:
        desc.insert(3, "Emphases: {}".format(emphases_desc(info['emphases'])))
    if info['param_scale']:
        desc.insert(5, "Scaled params: {}".format(
                                        param_scale_desc(info['param_scale'])))
    if info['param_freeze']:
        desc.insert(5, "Frozen params: {}".format(
                                        ", ".join(info['param_freeze'])))
    if info['param_map']:
        desc.insert(5, "Params map: {}".format(
                indent(param_map_desc(info['param_map']), " " * 12).strip()))
    return desc
开发者ID:wrwrwr,项目名称:blackbox,代码行数:32,代码来源:iop.py


示例8: _format_loop_exception

    def _format_loop_exception(self, context, n):
        message = context.get('message', 'Unhandled exception in event loop')
        exception = context.get('exception')
        if exception is not None:
            exc_info = (type(exception), exception, exception.__traceback__)
        else:
            exc_info = None

        lines = []
        for key in sorted(context):
            if key in {'message', 'exception'}:
                continue
            value = context[key]
            if key == 'source_traceback':
                tb = ''.join(traceback.format_list(value))
                value = 'Object created at (most recent call last):\n'
                value += tb.rstrip()
            else:
                try:
                    value = repr(value)
                except Exception as ex:
                    value = ('Exception in __repr__ {!r}; '
                             'value type: {!r}'.format(ex, type(value)))
            lines.append('[{}]: {}\n\n'.format(key, value))

        if exc_info is not None:
            lines.append('[exception]:\n')
            formatted_exc = textwrap.indent(
                ''.join(traceback.format_exception(*exc_info)), '  ')
            lines.append(formatted_exc)

        details = textwrap.indent(''.join(lines), '    ')
        return '{:02d}. {}:\n{}\n'.format(n, message, details)
开发者ID:MagicStack,项目名称:asyncpg,代码行数:33,代码来源:__init__.py


示例9: print_scrape_results_http

def print_scrape_results_http(results, verbosity=1, view=False):
    """Print the results obtained by "http" method."""
    for t in results:
        for result in t:
            logger.info('{} links found! The search with the keyword "{}" yielded the result:{}'.format(
                len(result['results']), result['search_keyword'], result['num_results_for_kw']))
            if view:
                import webbrowser
                webbrowser.open(result['cache_file'])
            import textwrap

            for result_set in ('results', 'ads_main', 'ads_aside'):
                if result_set in result.keys():
                    print('### {} link results for "{}" ###'.format(len(result[result_set]), result_set))
                    for link_title, link_snippet, link_url, link_position in result[result_set]:
                        try:
                            print('  Link: {}'.format(urllib.parse.unquote(link_url.geturl())))
                        except AttributeError as ae:
                            print(ae)
                        if verbosity > 1:
                            print(
                                '  Title: \n{}'.format(textwrap.indent('\n'.join(textwrap.wrap(link_title, 50)), '\t')))
                            print(
                                '  Description: \n{}\n'.format(
                                    textwrap.indent('\n'.join(textwrap.wrap(link_snippet, 70)), '\t')))
                            print('*' * 70)
                            print()
开发者ID:Sdlearn,项目名称:GoogleScraper,代码行数:27,代码来源:core.py


示例10: __str__

 def __str__(self):
     if self.left or self.right:
         return '{}({},\n{},\n{}\n)'.format(type(self).__name__,
                 self.data,
                 textwrap.indent(str(self.left), ' '*4),
                 textwrap.indent(str(self.right), ' '*4))
     return repr(self)
开发者ID:rmccampbell,项目名称:PythonProjects,代码行数:7,代码来源:classes.py


示例11: galaxy

def galaxy(_galaxy):
    systems = []
    debug('showing the galaxy...')
    for c, s in _galaxy._systems.items():
        sys = indent(system(s), '  ')[2:]
        systems.append('{} {}'.format(c, sys))
    return 'Galaxy:\n{}'.format(indent('\n'.join(systems), '  '))
开发者ID:fretboardfreak,项目名称:space,代码行数:7,代码来源:format_object.py


示例12: check

    def check():
        name = f.__name__
        message = ""
        if f.__doc__:
            message = "\n" + textwrap.indent(f.__doc__, '    """ ')
        try:
            f()
            return True
        except AssertionError as e:
            if e.args:
                message = e.args[0].strip()
            exception_class, exception, trace = sys.exc_info()
            frames = traceback.extract_tb(trace)
            last = frames[len(frames) - 1]

            message_hr = textwrap.indent(message, "    ")

            assertion = "{3}".format(*last)
            position = "{0}:{1}".format(*last)

            report("{} ({}):".format(name, position))
            if message_hr:
                report("    --------------------------------")
                report("{}".format(message_hr))
                report("    --------------------------------")
            report("    {}".format(assertion))
            report("")
            return False
        except Exception as e:
            report_exc("{}:{}".format(name, message), traceback.format_exc())
            return False
开发者ID:utdb,项目名称:judged,代码行数:31,代码来源:lawful.py


示例13: __str__

 def __str__(self):
     o = self.fmt.format(**self.__dict__)
     for k, l in self.lines.items():
         o += textwrap.indent(str(l), prefix=k + ' ')
     for txt in self.texts:
         o += 'with string\n'
         o += textwrap.indent(str(txt), prefix='    ')
     return o
开发者ID:nielsmde,项目名称:tudplot,代码行数:8,代码来源:pygrace.py


示例14: status

    def status(self, workspacePath):
        status = ScmStatus()
        try:
            onCorrectBranch = False
            output = self.callGit(workspacePath, 'ls-remote' ,'--get-url')
            if output != self.__url:
                status.add(ScmTaint.switched,
                    "> URL: configured: '{}', actual: '{}'".format(self.__url, output))

            if self.__commit:
                output = self.callGit(workspacePath, 'rev-parse', 'HEAD')
                if output != self.__commit:
                    status.add(ScmTaint.switched,
                        "> commit: configured: '{}', actual: '{}'".format(self.__commit, output))
            elif self.__tag:
                output = self.callGit(workspacePath, 'tag', '--points-at', 'HEAD').splitlines()
                if self.__tag not in output:
                    actual = ("'" + ", ".join(output) + "'") if output else "not on any tag"
                    status.add(ScmTaint.switched,
                        "> tag: configured: '{}', actual: '{}'".format(self.__tag, actual))
            elif self.__branch:
                output = self.callGit(workspacePath, 'rev-parse', '--abbrev-ref', 'HEAD')
                if output != self.__branch:
                    status.add(ScmTaint.switched,
                        "> branch: configured: '{}', actual: '{}'".format(self.__branch, output))
                else:
                    output = self.callGit(workspacePath, 'log', '--oneline',
                        'refs/remotes/origin/'+self.__branch+'..HEAD')
                    if output:
                        status.add(ScmTaint.unpushed_main,
                            joinLines("> unpushed commits on {}:".format(self.__branch),
                                indent(output, '   ')))
                    onCorrectBranch = True

            # Check for modifications wrt. checked out commit
            output = self.callGit(workspacePath, 'status', '--porcelain')
            if output:
                status.add(ScmTaint.modified, joinLines("> modified:",
                    indent(output, '   ')))

            # The following shows all unpushed commits reachable by any ref
            # (local branches, stash, detached HEAD, etc).
            # Exclude HEAD if the configured branch is checked out to not
            # double-count them. Does not mark the SCM as dirty.
            what = ['--all', '--not', '--remotes']
            if onCorrectBranch: what.append('HEAD')
            output = self.callGit(workspacePath, 'log', '--oneline', '--decorate',
                *what)
            if output:
                status.add(ScmTaint.unpushed_local,
                    joinLines("> unpushed local commits:", indent(output, '   ')))

        except BuildError as e:
            status.add(ScmTaint.error, e.slogan)

        return status
开发者ID:jkloetzke,项目名称:bob,代码行数:56,代码来源:git.py


示例15: slope_a

def slope_a(a, cell_size=1, kern=None, degrees=True, verb=False, keep=False):
    """Return slope in degrees for an input array using 3rd order
    finite difference method for a 3x3 moing window view into the array.

    Requires:
    ---------
    - a : an input 2d array. X and Y represent coordinates of the Z values
    - cell_size : cell size, must be in the same units as X and Y
    - kern : kernel to use
    - degrees : True, returns degrees otherwise radians
    - verb : True, to print results
    - keep : False, to remove/squeeze extra dimensions
    - filter :
        np.array([[1, 2, 1], [2, 0, 2], [1, 2, 1]]) **current default

    Notes:
    ------

    ::

        dzdx: sum(col2 - col0)/8*cellsize
        dzdy: sum(row2 - row0)/8*celsize
        Assert the array is ndim=4 even if (1,z,y,x)
        general         dzdx      +    dzdy     =    dxyz
        [[a, b, c],  [[1, 0, 1],   [[1, 2, 1]       [[1, 2, 1]
         [d, e, f]    [2, 0, 2], +  [0, 0, 0]   =    [2, 0, 2],
         [g, h, i]    [1, 0, 1]]    [1, 2, 1]]       [1, 2, 1]]

    """
    frmt = """\n    :----------------------------------------:
    :{}\n    :input array...\n    {}\n    :slope values...\n    {!r:}
    :----------------------------------------:
    """
    # ---- stride the data and calculate slope for 3x3 sliding windows ----
    np.set_printoptions(edgeitems=10, linewidth=100, precision=1)
    a_s = stride(a, win=(3, 3), stepby=(1, 1))
    if a_s.ndim < 4:
        new_shape = (1,) * (4-len(a_s.shape)) + a_s.shape
        a_s = a_s.reshape(new_shape)
    #
    kern = kernels(kern)  # return the kernel if specified
    # ---- default filter, apply the filter to the array ----
    #
    dz_dx, dz_dy = filter_a(a_s, a_filter=kern, cell_size=cell_size)
    #
    s = np.sqrt(dz_dx**2 + dz_dy**2)
    if degrees:
        s = np.rad2deg(np.arctan(s))
    if not keep:
        s = np.squeeze(s)
    if verb:
        p = "    "
        args = ["Results for slope_a... ",
                indent(str(a), p), indent(str(s), p)]
        print(dedent(frmt).format(*args))
    return s
开发者ID:Dan-Patterson,项目名称:GIS,代码行数:56,代码来源:surface.py


示例16: build_cpp_api_main

def build_cpp_api_main(outputdir, rst_header, components):
    """Parse existing rst files (one for each class,
    + those for functions) generated for C++ API
    and collect them into  cpp_api.rst
    in sphinx/reference directory.

    Parameters
    ----------
    outputdir : Path()
         sphinx directory which contains rst files
         generated for the api (e.g. by doxy2swig)
    rst_header : string
         text to put on top of the python_api file.
    """

    mainrst_filename = Path(outputdir, 'cpp_api.rst')
    # list documented (cpp) packages
    docpp_dir = Path(outputdir, 'cpp')
    packages = [f for f in docpp_dir.glob('*')]
    packages = [p.name for p in packages if os.listdir(p)]
    # trick to print components in the expected order.
    packages = [p for p in components if p in packages]
    indent = 4 * ' '
    class_diag = 'Class diagrams (UML view)'
    class_diag += '\n' + len(class_diag) * '=' + '\n\n'
    class_diag += ':doc:`/reference/class_diagrams`\n\n'

    with open(mainrst_filename, 'w') as f:
        label = '.. _siconos_cpp_reference:\n\n\n'
        title = 'Siconos C/C++ API reference'
        title += '\n' + len(title) * '#' + '\n\n'
        title += 'This is the documentation of C/C++ interface to Siconos.\n\n\n'
        f.write(label)
        f.write(title)
        f.write(rst_header)
        tab_directive = '.. csv-table::\n'
        tab_directive += textwrap.indent(':widths: 60 40\n\n', indent)
        column_titles = '**Classes and structs**, **Files**\n'
        tab_directive += textwrap.indent(column_titles, indent)

        f.write(class_diag)
        for p in packages:
            title = p.title() + ' component\n'
            title += len(title) * '=' + '\n\n'
            ppath = 'cpp/' + p
            f.write(title)
            pgm_listings = 'Check :ref:`' + p + '_pgm_listings`'
            pgm_listings += ' for a complete list of headers for this component.'
            f.write(pgm_listings + '\n\n')
            #f.write(tab_directive)
            directive = '.. include:: ' + ppath + '/autodoc_classes.rst'
            directive += '\n'#','
            directive += '.. include:: ' + ppath + '/autodoc_files.rst\n'
            indent = ''
            f.write(textwrap.indent(directive, indent))
            f.write('\n')
开发者ID:siconos,项目名称:siconos,代码行数:56,代码来源:cpp2rst.py


示例17: __init__

 def __init__(self, module, objs, pckg_tree=None):
     self.name = module.split('.')
     if pckg_tree:
         pckg_tree.walk(self.name[1:], self)
     self._extractors = {}
     self._var_names = set()
     code = StringIO()
     for obj in objs:
         if isinstance(obj, RustFuncGen.Func):
             self._extractors[obj.name] = extractors = []
             params, pyconstructors, argnames = [], [], []
             pn = [x[0] for x in obj.parameters]
             for x, param in enumerate(obj.parameters):
                 argnames.append(param[0] + ', ')
                 pyarg_constructor = self._fn_arg.format(param[0])
                 p, _ = self.unwrap_types(param[1], "", "")
                 if p[0] != '(':
                     p = p[1:-1]
                 sig = param[0] + ': ' + p
                 if x + 1 != len(obj.parameters):
                     sig += ",\n"
                     pyarg_constructor += "\n"
                 params.append(indent(sig, tab * 3))
                 pyconstructors.append(indent(pyarg_constructor, tab * 3))
             signature, return_val = self.unwrap_types(
                 obj.rsreturn, "", "",
                 extractors=extractors,
                 arg_names=pn,
                 init=True,
                 parent="result")
             if signature[0] == '(':
                 return_type = "-> " + signature
             elif len(obj.rsreturn) == 1 \
                     and obj.rsreturn[0] == 'PyObject::None':
                 return_type, return_val = "", ""
             else:
                 return_type = "-> " + signature[1:-1]
             if len(argnames) > 0:
                 args = "(" + "".join(argnames) + "),"
             else:
                 args = "NoArgs,"
             body = self._fn_body.substitute(
                 name=obj.name,
                 convert="".join(pyconstructors),
                 args=args,
                 extract_values="".join(extractors),
                 return_value=return_val,
             )
             code.write(self._function.substitute(
                 name=obj.name,
                 parameters="".join(params),
                 return_type=return_type,
                 body=body,
             ))
     self._generated_functions = code
开发者ID:iduartgomez,项目名称:rustypy,代码行数:55,代码来源:pywrapper.py


示例18: fmt_field

 def fmt_field(key, value="", level=0):
     if "\n" in value:
         value = indent(dedent(value), get_setting("indent")).strip("\n")
         sep = "\n"
     elif value:
         sep = " "
     else:
         sep = ""
     key = str(key).replace("_", " ")
     leader = level * get_setting("indent")
     return indent(LabelColor(key + ":") + sep + value, leader)
开发者ID:KenKundert,项目名称:avendesora,代码行数:11,代码来源:account.py


示例19: visit_If

 def visit_If(self, node):
     test = self.visit(node.test)
     spaces = ' ' * 4
     body = textwrap.indent('\n'.join(map(self.visit, node.body)), spaces)
     if node.orelse:
         orelse = textwrap.indent(
             '\n'.join(map(self.visit, node.orelse)),
             spaces
         )
         return 'if {}:\n{}\nelse:\n{}'.format(test, body, orelse)
     return 'if {}:\n{}'.format(test, body)
开发者ID:cpcloud,项目名称:cysqlite3,代码行数:11,代码来源:gen.py


示例20: __call__

    def __call__(self, content=None, wd=None, sudo=False, sudoPwd=None):
        if self.path is not None:
            try:
                with open(self.path, 'r') as input_:
                    self._content = input_.read()
            except FileNotFoundError:
                pass

        content = self._content if content is None else content
        if isinstance(self.seek, str):
            rObj = re.compile(self.seek, re.DOTALL | re.MULTILINE)
            match = rObj.search(content)
            if match:
                tgt = match.string[match.start():match.end()]
                msg = log_message(
                    logging.DEBUG,
                    msg="Pattern {} matched {}".format(
                        rObj.pattern, tgt),
                    name=self._name)
                self._rv = "\n".join(
                    [rObj.sub(textwrap.indent(self.data, ' ' * self.indent),
                     content, count=0)] +
                    [""] * self.newlines
                )
            else:
                msg = log_message(
                    logging.WARNING,
                    msg="Pattern {} unmatched.".format(
                        rObj.pattern),
                    name=self._name)
                self._rv = ""

            yield msg

        elif self.seek:
            args = (
                [content] +
                [textwrap.indent(self.data, ' ' * self.indent)] +
                [""] * self.newlines
            )
            self._rv = "\n".join(args)
        else:
            args = (
                [textwrap.indent(self.data, ' ' * self.indent)] +
                [""] * self.newlines + [content]
            )
            self._rv = "\n".join(args)

        # yield log_message(logging.DEBUG, msg=self._rv, name=self._name)

        if self._rv is not None and self.path is not None:
            with open(self.path, 'w') as output:
                output.write(self._rv)
                output.flush()
开发者ID:tundish,项目名称:pyoncannon,代码行数:54,代码来源:modder.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python textwrap.wrap函数代码示例发布时间:2022-05-27
下一篇:
Python textwrap.fill函数代码示例发布时间: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