从邮箱数据文件中获取电子邮件地址

Fetching email address from mailbox data file

提问人:Mayur Dhandarphale 提问时间:7/31/2023 更新时间:7/31/2023 访问量:13

问:

我写了下面的程序。有没有更好的方法(有效的方法)来重写代码?

##Read 通过邮箱数据。找到以“From”开头的行,并将其拆分为单词。获取电子邮件 #address(第二个单词)并打印。还要计算“发件人”行的总数并在末尾打印。

with open("mbox-short.txt", mode='r') as f:
        data = f.readlines()
count=0
for line in data:
    words = line.split()
    if line.startswith ('From:'):  continue
    if line.startswith ('From'):  
      email_sent_by= words[1]
      print(email_sent_by)
      count=count+1
print('There were',count,'lines in the file with From as the first word.')
python-3.x 字符串 文件 全文搜索 邮箱

评论


答: 暂无答案