久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='5po1d'><style id='5po1d'><dir id='5po1d'><q id='5po1d'></q></dir></style></legend>
    <tfoot id='5po1d'></tfoot>

  1. <i id='5po1d'><tr id='5po1d'><dt id='5po1d'><q id='5po1d'><span id='5po1d'><b id='5po1d'><form id='5po1d'><ins id='5po1d'></ins><ul id='5po1d'></ul><sub id='5po1d'></sub></form><legend id='5po1d'></legend><bdo id='5po1d'><pre id='5po1d'><center id='5po1d'></center></pre></bdo></b><th id='5po1d'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5po1d'><tfoot id='5po1d'></tfoot><dl id='5po1d'><fieldset id='5po1d'></fieldset></dl></div>

    <small id='5po1d'></small><noframes id='5po1d'>

      <bdo id='5po1d'></bdo><ul id='5po1d'></ul>

    1. Python格式字符串中的寬度變量

      Variables for width in Python format string(Python格式字符串中的寬度變量)

          <tbody id='FuHYa'></tbody>

      1. <tfoot id='FuHYa'></tfoot>
          <bdo id='FuHYa'></bdo><ul id='FuHYa'></ul>
            <legend id='FuHYa'><style id='FuHYa'><dir id='FuHYa'><q id='FuHYa'></q></dir></style></legend>
              <i id='FuHYa'><tr id='FuHYa'><dt id='FuHYa'><q id='FuHYa'><span id='FuHYa'><b id='FuHYa'><form id='FuHYa'><ins id='FuHYa'></ins><ul id='FuHYa'></ul><sub id='FuHYa'></sub></form><legend id='FuHYa'></legend><bdo id='FuHYa'><pre id='FuHYa'><center id='FuHYa'></center></pre></bdo></b><th id='FuHYa'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FuHYa'><tfoot id='FuHYa'></tfoot><dl id='FuHYa'><fieldset id='FuHYa'></fieldset></dl></div>

              <small id='FuHYa'></small><noframes id='FuHYa'>

              • 本文介紹了Python格式字符串中的寬度變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                為了打印表格數據的標題,我只想使用一個格式字符串 line 和一個列寬規范 w1, w2, w3 (如果可能的話,甚至是 w = x, y, z.)

                In order to print a header for tabular data, I'd like to use only one format string line and one spec for column widths w1, w2, w3 (or even w = x, y, z if possible.)

                我看過 this 但 tabulate 等不要讓我像 format 那樣證明列中的內容.

                I've looked at this but tabulate etc. don't let me justify things in the column like format does.

                這種方法有效:

                head = 'eggs', 'bacon', 'spam'  
                w1, w2, w3 = 8, 7, 10  # column widths  
                line = '  {:{ul}>{w1}}  {:{ul}>{w2}}  {:{ul}>{w3}}'  
                under = 3 * '='  
                print line.format(*head, ul='', w1=w1, w2=w2, w3=w3)  
                print line.format(*under, ul='=', w1=w1, w2=w2, w3=w3)  
                

                我必須在格式字符串中有單獨的名稱作為寬度 {w1}, {w2}, ...嗎?{w[1]}{w[2]} 等嘗試給出 KeyErrorkeyword can't be an表達式.

                Must I have individual names as widths {w1}, {w2}, ... in the format string? Attempts like {w[1]}, {w[2]}, give either KeyError or keyword can't be an expression.

                另外我認為 w1=w1, w2=w2, w3=w3 不是很簡潔.有沒有更好的辦法?

                Also I think the w1=w1, w2=w2, w3=w3 is not very succinct. Is there a better way?

                推薦答案

                這是 jonrsharpe 對我的 OP 的評論,旨在可視化正在發生的事情.

                This is jonrsharpe's comment to my OP, worked out so as to visualise what's going on.

                line = '  {:{ul}>{w1}}  {:{ul}>{w2}}  {:{ul}>{w3}}'
                under = 3 * '_'
                
                head = 'sausage', 'rat', 'strawberry tart'
                
                # manual dict 
                v = {'w1': 8, 'w2':5, 'w3': 17}
                print line.format(*under, ul='_', **v)
                
                # auto dict
                widthl = [8, 7, 9]
                x = {'w{}'.format(index): value for index, value in enumerate(widthl, 1)}
                print line.format(*under, ul='_', **x)     
                

                關鍵是我希望能夠快速重新排列標題,而無需調整格式字符串.auto dict 很好地滿足了這個要求.

                The point is that I want to be able to quickly rearrange the header without having to tweak the format string. The auto dict meets that requirement very nicely.

                至于以這種方式填充字典:哇!

                As for filling a dict in this way: WOW!

                這篇關于Python格式字符串中的寬度變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

                • <small id='Cv4FC'></small><noframes id='Cv4FC'>

                  <legend id='Cv4FC'><style id='Cv4FC'><dir id='Cv4FC'><q id='Cv4FC'></q></dir></style></legend>

                      <i id='Cv4FC'><tr id='Cv4FC'><dt id='Cv4FC'><q id='Cv4FC'><span id='Cv4FC'><b id='Cv4FC'><form id='Cv4FC'><ins id='Cv4FC'></ins><ul id='Cv4FC'></ul><sub id='Cv4FC'></sub></form><legend id='Cv4FC'></legend><bdo id='Cv4FC'><pre id='Cv4FC'><center id='Cv4FC'></center></pre></bdo></b><th id='Cv4FC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Cv4FC'><tfoot id='Cv4FC'></tfoot><dl id='Cv4FC'><fieldset id='Cv4FC'></fieldset></dl></div>
                      <tfoot id='Cv4FC'></tfoot>
                          <tbody id='Cv4FC'></tbody>
                          <bdo id='Cv4FC'></bdo><ul id='Cv4FC'></ul>
                          主站蜘蛛池模板: 国产一区二区三区四区五区3d | 黄网站免费在线看 | 99精品欧美一区二区蜜桃免费 | 在线成人av | 欧美人妇做爰xxxⅹ性高电影 | 久久久久国产精品午夜一区 | 请别相信他免费喜剧电影在线观看 | a黄视频| 亚洲高清免费视频 | 中文字幕成人av | 久久久久成人精品亚洲国产 | 国产欧美视频一区二区 | 伊人影院在线观看 | 中文字幕欧美日韩 | 日韩精品久久一区 | 女人牲交视频一级毛片 | 91精品无人区卡一卡二卡三 | 激情五月婷婷综合 | 欧美日韩大陆 | 久久久久久久久久久久一区二区 | 日韩一区二区在线视频 | 免费成人高清 | 影音先锋欧美资源 | 精品国产成人 | 一区中文字幕 | 国产99视频精品免费播放照片 | 黄色在线免费看 | 国产精品久久久久久中文字 | 久久久91 | 国产xxxx搡xxxxx搡麻豆 | 91免费在线视频 | 中文字幕免费 | 亚洲91| 精品一区精品二区 | 91日韩在线 | 精品久久一区二区三区 | 欧产日产国产精品v | 99热精品在线 | 欧美精品欧美精品系列 | 成人免费视频在线观看 | 久久精品成人一区 |