<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Python 程序:合并郵件 > 原文: [https://www.programiz.com/python-programming/examples/merge-mails](https://www.programiz.com/python-programming/examples/merge-mails) #### 在此程序中,您將學習將郵件合并為一個。 要理解此示例,您應該了解以下 [Python 編程](/python-programming "Python tutorial")主題: * [Python 字符串方法](/python-programming/strings-method) * [Python 文件 I/O](/python-programming/file-operation) * * * 當我們想將相同的邀請發送給許多人時,郵件的正文不會更改。 僅名稱(可能還有地址)需要更改。 郵件合并是執行此操作的過程。 我們沒有單獨編寫每封郵件,而是為郵件正文提供了模板,并通過名稱列表將它們合并在一起以形成所有郵件。 ## 合并郵件的源代碼 ```py # Python program to mail merger # Names are in the file names.txt # Body of the mail is in body.txt # open names.txt for reading with open("names.txt",'r',encoding = 'utf-8') as names_file: # open body.txt for reading with open("body.txt",'r',encoding = 'utf-8') as body_file: # read entire content of the body body = body_file.read() # iterate over names for name in names_file: mail = "Hello "+name+body # write the mails to individual files with open(name.strip()+".txt",'w',encoding = 'utf-8') as mail_file: mail_file.write(mail) ``` 對于此程序,我們將所有名稱寫在文件`"names.txt"`中的不同行中。 正文位于`"body.txt"`文件中。 我們以讀取模式打開兩個文件,并使用`for`循環遍歷每個名??稱。 創建了一個名為`"name.txt"`的新文件,其中`name`是該人的名字。 我們使用`strip()`方法清除前導和尾隨空格(從文件中讀取一行還讀取換行符`'\n'`)。 最后,我們使用`write()`方法將郵件的內容寫入此文件。 了解更多有關 Python 中[文件的信息](/python-programming/file-operation)。
                  <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>

                              哎呀哎呀视频在线观看