<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 習題 20: 函數和文件 回憶一下函數的要點,然后一邊做這節練習,一邊注意一下函數和文件是如何在一起協作發揮作用的。 <table class="highlighttable"><tbody><tr><td class="linenos"> <div class="linenodiv"> <pre> 1&#13; 2&#13; 3&#13; 4&#13; 5&#13; 6&#13; 7&#13; 8&#13; 9&#13; 10&#13; 11&#13; 12&#13; 13&#13; 14&#13; 15&#13; 16&#13; 17&#13; 18&#13; 19&#13; 20&#13; 21&#13; 22&#13; 23&#13; 24&#13; 25&#13; 26&#13; 27&#13; 28&#13; 29&#13; 30&#13; 31&#13; 32&#13; 33</pre> </div> </td> <td class="code"> <div class="highlight"> <pre>from sys import argv&#13; &#13; script, input_file = argv&#13; &#13; def print_all(f):&#13; print f.read()&#13; &#13; def rewind(f):&#13; f.seek(0)&#13; &#13; def print_a_line(line_count, f):&#13; print line_count, f.readline()&#13; &#13; current_file = open(input_file)&#13; &#13; print "First let's print the whole file:\n"&#13; &#13; print_all(current_file)&#13; &#13; print "Now let's rewind, kind of like a tape."&#13; &#13; rewind(current_file)&#13; &#13; print "Let's print three lines:"&#13; &#13; current_line = 1&#13; print_a_line(current_line, current_file)&#13; &#13; current_line = current_line + 1&#13; print_a_line(current_line, current_file)&#13; &#13; current_line = current_line + 1&#13; print_a_line(current_line, current_file)&#13; </pre> </div> </td> </tr></tbody></table> 特別注意一下,每次運行 print_a_line 時,我們是怎樣傳遞當前的行號信息的。 ### 你應該看到的結果 ~~~ $ python ex20.py test.txt First let's print the whole file: To all the people out there. I say I don't like my hair. I need to shave it off. Now let's rewind, kind of like a tape. Let's print three lines: 1 To all the people out there. 2 I say I don't like my hair. 3 I need to shave it off. $ ~~~ ### 加分習題 1. 通讀腳本,在每行之前加上注解,以理解腳本里發生的事情。 1. 每次 print_a_line 運行時,你都傳遞了一個叫 current_line 的變量。在每次調用函數時,打印出 current_line 的至,跟蹤一下它在 print_a_line 中是怎樣變成 line_count 的。 1. 找出腳本中每一個用到函數的地方。檢查 def 一行,確認參數沒有用錯。 1. 上網研究一下 file 中的 seek 函數是做什么用的。試著運行 pydocfile 看看能不能學到更多。 1. 研究一下 += 這個簡寫操作符的作用,寫一個腳本,把這個操作符用在里邊試一下。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看