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


Python cStringIO.writelines方法代码示例

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


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

示例1: _html_

# 需要导入模块: from six.moves import cStringIO [as 别名]
# 或者: from six.moves.cStringIO import writelines [as 别名]

#.........这里部分代码省略.........
            <div class="notruncate">
            <table  class="table_form">
            <tbody>
            <tr class ="row-a">
            <td><script type="math/tex">\sin(x)</script></td>
            <td><script type="math/tex">x</script></td>
            <td>text</td>
            </tr>
            <tr class ="row-b">
            <td><script type="math/tex">1</script></td>
            <td><script type="math/tex">34342</script></td>
            <td><script type="math/tex">3</script></td>
            </tr>
            <tr class ="row-a">
            <td><script type="math/tex">\left(\begin{array}{rr}
            1 & 0 \\
            0 & 1
            \end{array}\right)</script></td>
            <td><script type="math/tex">5</script></td>
            <td><script type="math/tex">6</script></td>
            </tr>
            </tbody>
            </table>
            </div>

        Note that calling ``html(table(...))`` has the same effect as
        calling ``table(...)._html_()``::

            sage: T = table([["$x$", "$\sin(x)$"]] + [(x,n(sin(x), digits=2)) for x in [0..3]], header_row=True, frame=True)
            sage: T
            +-----+-----------+
            | $x$ | $\sin(x)$ |
            +=====+===========+
            | 0   | 0.00      |
            +-----+-----------+
            | 1   | 0.84      |
            +-----+-----------+
            | 2   | 0.91      |
            +-----+-----------+
            | 3   | 0.14      |
            +-----+-----------+
            sage: print(html(T))
            <div class="notruncate">
            <table border="1" class="table_form">
            <tbody>
            <tr>
            <th><script type="math/tex">x</script></th>
            <th><script type="math/tex">\sin(x)</script></th>
            </tr>
            <tr class ="row-a">
            <td><script type="math/tex">0</script></td>
            <td><script type="math/tex">0.00</script></td>
            </tr>
            <tr class ="row-b">
            <td><script type="math/tex">1</script></td>
            <td><script type="math/tex">0.84</script></td>
            </tr>
            <tr class ="row-a">
            <td><script type="math/tex">2</script></td>
            <td><script type="math/tex">0.91</script></td>
            </tr>
            <tr class ="row-b">
            <td><script type="math/tex">3</script></td>
            <td><script type="math/tex">0.14</script></td>
            </tr>
            </tbody>
            </table>
            </div>
        """
        import types
        from itertools import cycle
        rows = self._rows
        header_row = self._options['header_row']
        if self._options['frame']:
            frame = 'border="1"'
        else:
            frame = ''
        s = StringIO()
        if rows:
            s.writelines([
                # If the table has < 100 rows, don't truncate the output in the notebook
                '<div class="notruncate">\n' if len(rows) <= 100 else '<div class="truncate">' ,
                '<table {} class="table_form">\n'.format(frame),
                '<tbody>\n',
            ])
            # First row:
            if header_row:
                s.write('<tr>\n')
                self._html_table_row(s, rows[0], header=header_row)
                s.write('</tr>\n')
                rows = rows[1:]

            # Other rows:
            for row_class, row in zip(cycle(["row-a", "row-b"]), rows):
                s.write('<tr class ="{}">\n'.format(row_class))
                self._html_table_row(s, row, header=False)
                s.write('</tr>\n')
            s.write('</tbody>\n</table>\n</div>')
        from sage.misc.html import HtmlFragment
        return HtmlFragment(s.getvalue())
开发者ID:mcognetta,项目名称:sage,代码行数:104,代码来源:table.py


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