{"id":1102807,"date":"2025-01-08T16:03:50","date_gmt":"2025-01-08T08:03:50","guid":{"rendered":""},"modified":"2025-01-08T16:03:53","modified_gmt":"2025-01-08T08:03:53","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e6%8a%bd%e5%8f%96%e6%8c%87%e5%ae%9a%e6%96%87%e6%9c%ac%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1102807.html","title":{"rendered":"\u5982\u4f55\u7528python\u62bd\u53d6\u6307\u5b9a\u6587\u672c\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064928\/cfc864bf-8db1-4d44-9470-107fcb7d41d8.webp\" alt=\"\u5982\u4f55\u7528python\u62bd\u53d6\u6307\u5b9a\u6587\u672c\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u8981\u7528Python\u62bd\u53d6\u6307\u5b9a\u6587\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7279\u5b9a\u6a21\u5f0f\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u5904\u7406\u7279\u5b9a\u6587\u4ef6\u683c\u5f0f<\/strong>\u3002\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528Python\u5185\u7f6e\u7684\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\u8bfb\u53d6\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u5b57\u7b26\u4e32\u64cd\u4f5c\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u6240\u9700\u5185\u5bb9\u3002\u8ba9\u6211\u4eec\u8be6\u7ec6\u63cf\u8ff0\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u5b8c\u6210\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>\u6587\u4ef6\u8bfb\u5199\u57fa\u7840<\/h3>\n<\/p>\n<p><h4>\u4e00\u3001\u8bfb\u53d6\u6587\u672c\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684<code>open<\/code>\u51fd\u6570\u6765\u6253\u5f00\u6587\u4ef6\u3002\u4f7f\u7528<code>open<\/code>\u51fd\u6570\u53ef\u4ee5\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u5e76\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5f00\u6587\u4ef6<\/p>\n<p>with open(&#39;example.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<p>print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c<code>with open<\/code>\u8bed\u53e5\u7528\u4e8e\u6253\u5f00\u6587\u4ef6\u5e76\u786e\u4fdd\u5728\u5904\u7406\u5b8c\u6210\u540e\u81ea\u52a8\u5173\u95ed\u6587\u4ef6\u3002<code>&#39;r&#39;<\/code>\u8868\u793a\u8bfb\u53d6\u6a21\u5f0f\uff0c<code>encoding=&#39;utf-8&#39;<\/code>\u786e\u4fdd\u6587\u4ef6\u4ee5UTF-8\u7f16\u7801\u8bfb\u53d6\u3002<code>file.read()<\/code>\u65b9\u6cd5\u8bfb\u53d6\u6587\u4ef6\u7684\u5168\u90e8\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h4>\u4e8c\u3001\u9010\u884c\u8bfb\u53d6\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u9010\u884c\u5904\u7406\u6587\u4ef6\u5185\u5bb9\u4f1a\u66f4\u65b9\u4fbf\uff0c\u5c24\u5176\u662f\u5f53\u6587\u4ef6\u8f83\u5927\u65f6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9010\u884c\u8bfb\u53d6\u6587\u4ef6<\/p>\n<p>with open(&#39;example.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    for line in file:<\/p>\n<p>        print(line.strip())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>file<\/code>\u5bf9\u8c61\u662f\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u53ef\u4ee5\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3002<code>line.strip()<\/code>\u7528\u4e8e\u53bb\u9664\u884c\u9996\u548c\u884c\u5c3e\u7684\u7a7a\u767d\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><h3>\u5b57\u7b26\u4e32\u64cd\u4f5c<\/h3>\n<\/p>\n<p><h4>\u4e09\u3001\u67e5\u627e\u7279\u5b9a\u6587\u672c<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u5b57\u7b26\u4e32\u7684\u5185\u7f6e\u65b9\u6cd5\u53ef\u4ee5\u67e5\u627e\u548c\u5904\u7406\u7279\u5b9a\u6587\u672c\u3002\u4f8b\u5982\uff0c\u67e5\u627e\u6587\u4ef6\u4e2d\u662f\u5426\u5305\u542b\u7279\u5b9a\u5173\u952e\u8bcd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">keyword = &quot;Python&quot;<\/p>\n<p>with open(&#39;example.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<p>if keyword in content:<\/p>\n<p>    print(f&quot;\u627e\u5230\u5173\u952e\u8bcd: {keyword}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>str.find()<\/code>\u6216<code>str.index()<\/code>\u65b9\u6cd5\u83b7\u53d6\u5173\u952e\u8bcd\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><h4>\u56db\u3001\u63d0\u53d6\u7279\u5b9a\u6587\u672c<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u9700\u8981\u4ece\u6587\u4ef6\u4e2d\u63d0\u53d6\u7279\u5b9a\u683c\u5f0f\u7684\u6587\u672c\uff0c\u4f8b\u5982\u6240\u6709\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5b8c\u6210\u6b64\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>with open(&#39;example.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<h2><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u67e5\u627e\u6240\u6709\u7535\u5b50\u90ae\u4ef6\u5730\u5740<\/strong><\/h2>\n<p>em<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ls = re.findall(r&#39;\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b&#39;, content)<\/p>\n<p>print(emails)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><h4>\u4e94\u3001\u5904\u7406\u7279\u5b9a\u6587\u4ef6\u683c\u5f0f<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u4e9b\u7279\u5b9a\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u5982CSV\u3001JSON\u3001XML\u7b49\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u7b2c\u4e09\u65b9\u5e93\u6765\u5904\u7406\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>pandas<\/code>\u5e93\u5904\u7406CSV\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>df = pd.read_csv(&#39;example.csv&#39;)<\/p>\n<p>print(df.head())<\/p>\n<h2><strong>\u63d0\u53d6\u7279\u5b9a\u5217\u7684\u6570\u636e<\/strong><\/h2>\n<p>emails = df[&#39;email&#39;]<\/p>\n<p>print(emails)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6b63\u5219\u8868\u8fbe\u5f0f<\/h3>\n<\/p>\n<p><h4>\u516d\u3001\u590d\u6742\u6587\u672c\u63d0\u53d6<\/h4>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u6587\u672c\u5339\u914d\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5904\u7406\u590d\u6742\u7684\u6587\u672c\u63d0\u53d6\u4efb\u52a1\u3002\u4f8b\u5982\uff0c\u4ece\u6587\u4ef6\u4e2d\u63d0\u53d6\u6240\u6709\u7b26\u5408\u7279\u5b9a\u6a21\u5f0f\u7684\u6587\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>with open(&#39;example.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<h2><strong>\u63d0\u53d6\u6240\u6709\u7b26\u5408\u7279\u5b9a\u6a21\u5f0f\u7684\u6587\u672c<\/strong><\/h2>\n<p>pattern = r&#39;\\b\\d{3}-\\d{2}-\\d{4}\\b&#39;  # \u5339\u914dSSN\u683c\u5f0f<\/p>\n<p>matches = re.findall(pattern, content)<\/p>\n<p>print(matches)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5904\u7406\u5927\u6587\u4ef6<\/h3>\n<\/p>\n<p><h4>\u4e03\u3001\u9010\u884c\u5904\u7406\u5927\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u6587\u4ef6\uff0c\u9010\u884c\u5904\u7406\u53ef\u4ee5\u8282\u7701\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9010\u884c\u8bfb\u53d6\u5e76\u5904\u7406\u5927\u6587\u4ef6<\/p>\n<p>with open(&#39;large_file.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>    for line in file:<\/p>\n<p>        # \u5728\u8fd9\u91cc\u5904\u7406\u6bcf\u4e00\u884c<\/p>\n<p>        if &quot;keyword&quot; in line:<\/p>\n<p>            print(line.strip())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u8fdb\u9636\u7528\u6cd5<\/h3>\n<\/p>\n<p><h4>\u516b\u3001\u4f7f\u7528\u751f\u6210\u5668\u5904\u7406\u5927\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u5904\u7406\u5927\u6587\u4ef6\u7684\u9ad8\u6548\u65b9\u6cd5\uff0c\u53ef\u4ee5\u907f\u514d\u4e00\u6b21\u6027\u5c06\u6587\u4ef6\u5185\u5bb9\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def read_large_file(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>        for line in file:<\/p>\n<p>            yield line<\/p>\n<h2><strong>\u4f7f\u7528\u751f\u6210\u5668\u5904\u7406\u5927\u6587\u4ef6<\/strong><\/h2>\n<p>for line in read_large_file(&#39;large_file.txt&#39;):<\/p>\n<p>    if &quot;keyword&quot; in line:<\/p>\n<p>        print(line.strip())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u7ed3\u5408\u4f7f\u7528<\/h3>\n<\/p>\n<p><h4>\u4e5d\u3001\u7efc\u5408\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u7ed3\u5408\u4e0a\u9762\u7684\u6280\u672f\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7efc\u5408\u793a\u4f8b\uff0c\u4ece\u6587\u4ef6\u4e2d\u63d0\u53d6\u7279\u5b9a\u6587\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>def extract_emails(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>        content = file.read()<\/p>\n<p>    # \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u6240\u6709\u7535\u5b50\u90ae\u4ef6\u5730\u5740<\/p>\n<p>    emails = re.findall(r&#39;\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b&#39;, content)<\/p>\n<p>    return emails<\/p>\n<p>def extract_phone_numbers(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as file:<\/p>\n<p>        content = file.read()<\/p>\n<p>    # \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u53d6\u6240\u6709\u7535\u8bdd\u53f7\u7801<\/p>\n<p>    phone_numbers = re.findall(r&#39;\\b\\d{3}-\\d{3}-\\d{4}\\b&#39;, content)<\/p>\n<p>    return phone_numbers<\/p>\n<h2><strong>\u63d0\u53d6\u5e76\u6253\u5370\u7ed3\u679c<\/strong><\/h2>\n<p>emails = extract_emails(&#39;example.txt&#39;)<\/p>\n<p>phone_numbers = extract_phone_numbers(&#39;example.txt&#39;)<\/p>\n<p>print(&quot;Emails:&quot;, emails)<\/p>\n<p>print(&quot;Phone Numbers:&quot;, phone_numbers)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Python\u62bd\u53d6\u6307\u5b9a\u6587\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5185\u7f6e\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c\u3001\u6b63\u5219\u8868\u8fbe\u5f0f\u548c\u7b2c\u4e09\u65b9\u5e93\u7b49\u65b9\u5f0f\u5b8c\u6210\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u573a\u666f\u548c\u4f18\u7f3a\u70b9\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u6548\u7387\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u5185\u5bb9\uff0c\u4f60\u5e94\u8be5\u5df2\u7ecf\u638c\u63e1\u4e86\u5982\u4f55\u4f7f\u7528Python\u8bfb\u53d6\u6587\u672c\u6587\u4ef6\u3001\u67e5\u627e\u548c\u63d0\u53d6\u7279\u5b9a\u6587\u672c\u5185\u5bb9\u7684\u65b9\u6cd5\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u6280\u672f\u624b\u6bb5\uff0c\u76f8\u4fe1\u4f60\u80fd\u9ad8\u6548\u5730\u5b8c\u6210\u6587\u672c\u5904\u7406\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8bfb\u53d6\u6587\u672c\u6587\u4ef6\u7684\u5185\u5bb9\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>open()<\/code>\u51fd\u6570\u6765\u8bfb\u53d6\u6587\u672c\u6587\u4ef6\u3002\u901a\u8fc7\u6307\u5b9a\u6587\u4ef6\u8def\u5f84\u548c\u6a21\u5f0f\uff08\u4f8b\u5982<code>&#39;r&#39;<\/code>\u8868\u793a\u53ea\u8bfb\uff09\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u83b7\u53d6\u6587\u4ef6\u7684\u5185\u5bb9\u3002\u4f7f\u7528<code>read()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u8bfb\u53d6\u6574\u4e2a\u6587\u4ef6\uff0c<code>readline()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u9010\u884c\u8bfb\u53d6\uff0c\u800c<code>readlines()<\/code>\u65b9\u6cd5\u5219\u4f1a\u5c06\u6587\u4ef6\u7684\u6240\u6709\u884c\u4f5c\u4e3a\u5217\u8868\u8fd4\u56de\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">with open(&#39;file.txt&#39;, &#39;r&#39;) as file:\n    content = file.read()\n    print(content)\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u62bd\u53d6\u6587\u672c\u6587\u4ef6\u4e2d\u7684\u6570\u636e\uff1f<\/strong><br \/>\u4e3a\u4e86\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u62bd\u53d6\u6570\u636e\uff0c\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u548c\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u6cd5\u3002\u9996\u5148\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\uff0c\u7136\u540e\u5728\u5faa\u73af\u4e2d\u68c0\u67e5\u6bcf\u4e00\u884c\u662f\u5426\u7b26\u5408\u6761\u4ef6\uff0c\u7b26\u5408\u6761\u4ef6\u7684\u884c\u53ef\u4ee5\u88ab\u5b58\u50a8\u5230\u4e00\u4e2a\u65b0\u5217\u8868\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5047\u8bbe\u9700\u8981\u62bd\u53d6\u5305\u542b\u201cPython\u201d\u7684\u884c\uff1a  <\/p>\n<pre><code class=\"language-python\">with open(&#39;file.txt&#39;, &#39;r&#39;) as file:\n    lines = file.readlines()\n    filtered_lines = [line for line in lines if &#39;Python&#39; in line]\n    print(filtered_lines)\n<\/code><\/pre>\n<p><strong>\u4f7f\u7528Python\u62bd\u53d6\u6587\u672c\u6587\u4ef6\u4e2d\u7684\u7279\u5b9a\u683c\u5f0f\u6570\u636e\u9700\u8981\u6ce8\u610f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728\u62bd\u53d6\u7279\u5b9a\u683c\u5f0f\u7684\u6570\u636e\u65f6\uff0c\u786e\u4fdd\u6b63\u786e\u8bc6\u522b\u5e76\u5904\u7406\u6587\u4ef6\u7f16\u7801\u548c\u884c\u7ed3\u675f\u7b26\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ef\u80fd\u4f7f\u7528\u4e0d\u540c\u7684\u884c\u7ed3\u675f\u7b26\uff08\u5982<code>\\n<\/code>\u6216<code>\\r\\n<\/code>\uff09\uff0c\u5728\u8bfb\u53d6\u6587\u4ef6\u65f6\u53ef\u4ee5\u4f7f\u7528<code>newline<\/code>\u53c2\u6570\u6765\u6307\u5b9a\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5e2e\u52a9\u66f4\u7cbe\u786e\u5730\u5339\u914d\u7279\u5b9a\u6a21\u5f0f\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u8981\u62bd\u53d6\u6240\u6709\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import re\n\nwith open(&#39;file.txt&#39;, &#39;r&#39;) as file:\n    content = file.read()\n    emails = re.findall(r&#39;\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b&#39;, content)\n    print(emails)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u62bd\u53d6\u6240\u9700\u7684\u7279\u5b9a\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u7528Python\u62bd\u53d6\u6307\u5b9a\u6587\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u6587\u4ef6\u64cd\u4f5c\u51fd\u6570\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7279\u5b9a\u6a21\u5f0f\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u5904\u7406\u7279\u5b9a [&hellip;]","protected":false},"author":3,"featured_media":1102816,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1102807"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1102807"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1102807\/revisions"}],"predecessor-version":[{"id":1102818,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1102807\/revisions\/1102818"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1102816"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1102807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1102807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1102807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}