{"id":1184773,"date":"2025-01-15T19:30:38","date_gmt":"2025-01-15T11:30:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1184773.html"},"modified":"2025-01-15T19:30:44","modified_gmt":"2025-01-15T11:30:44","slug":"btw%e6%a0%bc%e5%bc%8f%e7%94%a8python%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1184773.html","title":{"rendered":"btw\u683c\u5f0f\u7528python\u5982\u4f55\u6253\u5f00"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25134108\/486f630e-6a57-492f-b2fa-a66fbf516a82.webp\" alt=\"btw\u683c\u5f0f\u7528python\u5982\u4f55\u6253\u5f00\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u6253\u5f00BTW\u683c\u5f0f\u6587\u4ef6\u6709\u51e0\u79cd\u65b9\u6cd5\u3002<strong>\u4f7f\u7528Python\u7684\u6587\u4ef6\u5904\u7406\u5e93\u3001\u4f7f\u7528\u4e13\u95e8\u7684\u7b2c\u4e09\u65b9\u5e93<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u6587\u4ef6\u5904\u7406\u5e93\u662f\u4e00\u79cd\u6bd4\u8f83\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u800c\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u5219\u53ef\u4ee5\u63d0\u4f9b\u66f4\u591a\u7684\u529f\u80fd\u548c\u66f4\u597d\u7684\u517c\u5bb9\u6027\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u7684\u89e3\u91ca\u548c\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528Python\u7684\u6587\u4ef6\u5904\u7406\u5e93<\/h3>\n<\/p>\n<p><p>Python\u81ea\u5e26\u7684\u6587\u4ef6\u5904\u7406\u5e93\u53ef\u4ee5\u7528\u6765\u8bfb\u53d6\u548c\u5199\u5165\u5404\u79cd\u6587\u4ef6\u683c\u5f0f\u3002\u5bf9\u4e8eBTW\u683c\u5f0f\u6587\u4ef6\uff0c\u9996\u5148\u9700\u8981\u77e5\u9053\u6587\u4ef6\u7684\u5177\u4f53\u7ed3\u6784\u548c\u5185\u5bb9\uff0c\u7136\u540e\u6839\u636e\u5176\u7ed3\u6784\u8fdb\u884c\u89e3\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def read_btw_file(file_path):<\/p>\n<p>    with open(file_path, &#39;rb&#39;) as file:<\/p>\n<p>        content = file.read()<\/p>\n<p>        # \u6839\u636eBTW\u6587\u4ef6\u7684\u5177\u4f53\u7ed3\u6784\u89e3\u6790\u5185\u5bb9<\/p>\n<p>        # \u8fd9\u91cc\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5b9e\u9645\u60c5\u51b5\u53ef\u80fd\u9700\u8981\u66f4\u590d\u6742\u7684\u89e3\u6790\u903b\u8f91<\/p>\n<p>        return content<\/p>\n<p>def write_btw_file(file_path, content):<\/p>\n<p>    with open(file_path, &#39;wb&#39;) as file:<\/p>\n<p>        file.write(content)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>content = read_btw_file(btw_file_path)<\/p>\n<p>print(content)<\/p>\n<p>new_content = b&#39;new content for BTW file&#39;<\/p>\n<p>write_btw_file(&#39;new_example.btw&#39;, new_content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><p>\u6709\u4e9b\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u7279\u5b9a\u6587\u4ef6\u683c\u5f0f\u7684\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u5927\u5927\u7b80\u5316BTW\u6587\u4ef6\u7684\u5904\u7406\u8fc7\u7a0b\u3002\u6bd4\u5982\uff0c\u5982\u679cBTW\u6587\u4ef6\u662f\u6307Bartender\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528Bartender\u7684API\u6765\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>Bartender API<\/h4>\n<\/p>\n<p><p>Bartender\u662f\u4e00\u6b3e\u4e13\u4e1a\u7684\u6807\u7b7e\u8bbe\u8ba1\u548c\u6761\u7801\u6253\u5370\u8f6f\u4ef6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684API\u63a5\u53e3\u6765\u64cd\u4f5cBTW\u683c\u5f0f\u6587\u4ef6\u3002Bartender\u7684API\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5305\u62ecPython\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5Bartender\u8f6f\u4ef6\u5e76\u914d\u7f6e\u597dAPI\u63a5\u53e3\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528Python\u811a\u672c\u6765\u8c03\u7528Bartender\u7684API\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import win32com.client<\/p>\n<p>def open_btw_file(file_path):<\/p>\n<p>    btApp = win32com.client.Dispatch(&#39;Bartender.Application&#39;)<\/p>\n<p>    btFormat = btApp.Formats.Open(file_path, False, &quot;&quot;)<\/p>\n<p>    return btFormat<\/p>\n<p>def print_btw_file(btFormat):<\/p>\n<p>    btFormat.PrintOut(False, False)<\/p>\n<p>def close_btw_file(btFormat):<\/p>\n<p>    btFormat.Close(1)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>btFormat = open_btw_file(btw_file_path)<\/p>\n<p>print_btw_file(btFormat)<\/p>\n<p>close_btw_file(btFormat)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>BTW\u6587\u4ef6\u7ed3\u6784\u89e3\u6790<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u662f\u4e00\u79cd\u81ea\u5b9a\u4e49\u683c\u5f0f\uff0c\u9700\u8981\u624b\u52a8\u89e3\u6790\u5176\u7ed3\u6784\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684struct\u6a21\u5757\u8fdb\u884c\u4e8c\u8fdb\u5236\u6570\u636e\u89e3\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import struct<\/p>\n<p>def parse_btw_file(file_path):<\/p>\n<p>    with open(file_path, &#39;rb&#39;) as file:<\/p>\n<p>        # \u8bfb\u53d6\u6587\u4ef6\u5934\u90e8\u4fe1\u606f<\/p>\n<p>        header = file.read(8)<\/p>\n<p>        # \u6839\u636e\u6587\u4ef6\u5934\u90e8\u4fe1\u606f\u89e3\u6790\u6570\u636e<\/p>\n<p>        data = struct.unpack(&#39;4sI&#39;, header)<\/p>\n<p>        print(data)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>parse_btw_file(btw_file_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p><strong>\u4f7f\u7528Python\u7684\u6587\u4ef6\u5904\u7406\u5e93\u3001\u4f7f\u7528\u4e13\u95e8\u7684\u7b2c\u4e09\u65b9\u5e93<\/strong>\u90fd\u662f\u6253\u5f00BTW\u683c\u5f0f\u6587\u4ef6\u7684\u6709\u6548\u65b9\u6cd5\u3002\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u548cBTW\u6587\u4ef6\u7684\u7c7b\u578b\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u5982\u679c\u662fBartender\u683c\u5f0f\u7684BTW\u6587\u4ef6\uff0c\u53ef\u4ee5\u5229\u7528Bartender\u7684API\u6765\u64cd\u4f5c\uff0c\u80fd\u5927\u5927\u7b80\u5316\u4ee3\u7801\u548c\u63d0\u9ad8\u6548\u7387\u3002\u5982\u679c\u662f\u81ea\u5b9a\u4e49\u683c\u5f0f\u7684BTW\u6587\u4ef6\uff0c\u5219\u9700\u8981\u4e86\u89e3\u6587\u4ef6\u7684\u5177\u4f53\u7ed3\u6784\u5e76\u8fdb\u884c\u624b\u52a8\u89e3\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Python\u7684\u6587\u4ef6\u5904\u7406\u5e93<\/h3>\n<\/p>\n<p><p>Python\u81ea\u5e26\u7684\u6587\u4ef6\u5904\u7406\u5e93\u975e\u5e38\u5f3a\u5927\uff0c\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u5404\u79cd\u6587\u4ef6\u683c\u5f0f\u3002\u5bf9\u4e8eBTW\u683c\u5f0f\u6587\u4ef6\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3\u5176\u5177\u4f53\u7ed3\u6784\uff0c\u7136\u540e\u6839\u636e\u7ed3\u6784\u8fdb\u884c\u89e3\u6790\u548c\u5904\u7406\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Python\u8bfb\u53d6\u548c\u5199\u5165BTW\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def read_btw_file(file_path):<\/p>\n<p>    with open(file_path, &#39;rb&#39;) as file:<\/p>\n<p>        content = file.read()<\/p>\n<p>        # \u6839\u636eBTW\u6587\u4ef6\u7684\u5177\u4f53\u7ed3\u6784\u89e3\u6790\u5185\u5bb9<\/p>\n<p>        # \u8fd9\u91cc\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5b9e\u9645\u60c5\u51b5\u53ef\u80fd\u9700\u8981\u66f4\u590d\u6742\u7684\u89e3\u6790\u903b\u8f91<\/p>\n<p>        return content<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>content = read_btw_file(btw_file_path)<\/p>\n<p>print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_btw_file(file_path, content):<\/p>\n<p>    with open(file_path, &#39;wb&#39;) as file:<\/p>\n<p>        file.write(content)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_content = b&#39;new content for BTW file&#39;<\/p>\n<p>write_btw_file(&#39;new_example.btw&#39;, new_content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u67d0\u4e9b\u7279\u5b9a\u683c\u5f0f\u7684BTW\u6587\u4ef6\uff0c\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u548c\u9ad8\u6548\u3002\u6bd4\u5982\uff0cBartender\u683c\u5f0f\u7684BTW\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528Bartender\u7684API\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5\u548c\u914d\u7f6eBartender<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5Bartender\u8f6f\u4ef6\u5e76\u914d\u7f6e\u597dAPI\u63a5\u53e3\u3002\u53ef\u4ee5\u5728Bartender\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5\u8f6f\u4ef6\uff0c\u7136\u540e\u6309\u7167\u6587\u6863\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528Bartender API<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import win32com.client<\/p>\n<p>def open_btw_file(file_path):<\/p>\n<p>    btApp = win32com.client.Dispatch(&#39;Bartender.Application&#39;)<\/p>\n<p>    btFormat = btApp.Formats.Open(file_path, False, &quot;&quot;)<\/p>\n<p>    return btFormat<\/p>\n<p>def print_btw_file(btFormat):<\/p>\n<p>    btFormat.PrintOut(False, False)<\/p>\n<p>def close_btw_file(btFormat):<\/p>\n<p>    btFormat.Close(1)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>btFormat = open_btw_file(btw_file_path)<\/p>\n<p>print_btw_file(btFormat)<\/p>\n<p>close_btw_file(btFormat)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001BTW\u6587\u4ef6\u7ed3\u6784\u89e3\u6790<\/h3>\n<\/p>\n<p><p>\u6709\u4e9bBTW\u6587\u4ef6\u662f\u81ea\u5b9a\u4e49\u683c\u5f0f\uff0c\u9700\u8981\u624b\u52a8\u89e3\u6790\u5176\u7ed3\u6784\u3002Python\u7684struct\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u89e3\u6790\u4e8c\u8fdb\u5236\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>\u4f7f\u7528struct\u6a21\u5757\u89e3\u6790BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import struct<\/p>\n<p>def parse_btw_file(file_path):<\/p>\n<p>    with open(file_path, &#39;rb&#39;) as file:<\/p>\n<p>        # \u8bfb\u53d6\u6587\u4ef6\u5934\u90e8\u4fe1\u606f<\/p>\n<p>        header = file.read(8)<\/p>\n<p>        # \u6839\u636e\u6587\u4ef6\u5934\u90e8\u4fe1\u606f\u89e3\u6790\u6570\u636e<\/p>\n<p>        data = struct.unpack(&#39;4sI&#39;, header)<\/p>\n<p>        print(data)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>parse_btw_file(btw_file_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528pandas\u5e93\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u5305\u542b\u7ed3\u6784\u5316\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528pandas\u5e93\u8fdb\u884c\u5904\u7406\u3002pandas\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u683c\u5f0f\u7684\u6570\u636e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6BTW\u6587\u4ef6\u5230DataFrame<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>def read_btw_to_dataframe(file_path):<\/p>\n<p>    # \u8bfb\u53d6BTW\u6587\u4ef6\u5185\u5bb9<\/p>\n<p>    with open(file_path, &#39;rb&#39;) as file:<\/p>\n<p>        content = file.read()<\/p>\n<p>    # \u5047\u8bbeBTW\u6587\u4ef6\u662fCSV\u683c\u5f0f\uff0c\u53ef\u4ee5\u76f4\u63a5\u8bfb\u53d6\u5230DataFrame<\/p>\n<p>    df = pd.read_csv(pd.compat.StringIO(content.decode(&#39;utf-8&#39;)))<\/p>\n<p>    return df<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>df = read_btw_to_dataframe(btw_file_path)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5c06DataFrame\u5199\u5165BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_dataframe_to_btw(df, file_path):<\/p>\n<p>    # \u5c06DataFrame\u8f6c\u6362\u4e3aCSV\u683c\u5f0f<\/p>\n<p>    content = df.to_csv(index=False)<\/p>\n<p>    # \u5199\u5165BTW\u6587\u4ef6<\/p>\n<p>    with open(file_path, &#39;wb&#39;) as file:<\/p>\n<p>        file.write(content.encode(&#39;utf-8&#39;))<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_df = pd.DataFrame({&#39;column1&#39;: [1, 2, 3], &#39;column2&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]})<\/p>\n<p>write_dataframe_to_btw(new_df, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528xlrd\u548cxlwt\u5e93\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u662fExcel\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528xlrd\u548cxlwt\u5e93\u8fdb\u884c\u8bfb\u53d6\u548c\u5199\u5165\u3002\u8fd9\u4e24\u4e2a\u5e93\u5206\u522b\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165Excel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6Excel\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import xlrd<\/p>\n<p>def read_excel_btw(file_path):<\/p>\n<p>    workbook = xlrd.open_workbook(file_path)<\/p>\n<p>    sheet = workbook.sheet_by_index(0)<\/p>\n<p>    data = []<\/p>\n<p>    for row_idx in range(sheet.nrows):<\/p>\n<p>        row = sheet.row_values(row_idx)<\/p>\n<p>        data.append(row)<\/p>\n<p>    return data<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>data = read_excel_btw(btw_file_path)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165Excel\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import xlwt<\/p>\n<p>def write_excel_btw(data, file_path):<\/p>\n<p>    workbook = xlwt.Workbook()<\/p>\n<p>    sheet = workbook.add_sheet(&#39;Sheet1&#39;)<\/p>\n<p>    for row_idx, row in enumerate(data):<\/p>\n<p>        for col_idx, value in enumerate(row):<\/p>\n<p>            sheet.write(row_idx, col_idx, value)<\/p>\n<p>    workbook.save(file_path)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_data = [[&#39;column1&#39;, &#39;column2&#39;], [1, &#39;a&#39;], [2, &#39;b&#39;], [3, &#39;c&#39;]]<\/p>\n<p>write_excel_btw(new_data, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528openpyxl\u5e93\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>openpyxl\u5e93\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u5904\u7406Excel\u6587\u4ef6\u7684\u5e93\uff0c\u652f\u6301\u8bfb\u53d6\u548c\u5199\u5165.xlsx\u683c\u5f0f\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6.xlsx\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import openpyxl<\/p>\n<p>def read_openpyxl_btw(file_path):<\/p>\n<p>    workbook = openpyxl.load_workbook(file_path)<\/p>\n<p>    sheet = workbook.active<\/p>\n<p>    data = []<\/p>\n<p>    for row in sheet.iter_rows(values_only=True):<\/p>\n<p>        data.append(row)<\/p>\n<p>    return data<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>data = read_openpyxl_btw(btw_file_path)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165.xlsx\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_openpyxl_btw(data, file_path):<\/p>\n<p>    workbook = openpyxl.Workbook()<\/p>\n<p>    sheet = workbook.active<\/p>\n<p>    for row in data:<\/p>\n<p>        sheet.append(row)<\/p>\n<p>    workbook.save(file_path)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_data = [[&#39;column1&#39;, &#39;column2&#39;], [1, &#39;a&#39;], [2, &#39;b&#39;], [3, &#39;c&#39;]]<\/p>\n<p>write_openpyxl_btw(new_data, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528json\u5e93\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u662fJSON\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684json\u5e93\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6JSON\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<p>def read_json_btw(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        data = json.load(file)<\/p>\n<p>    return data<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>data = read_json_btw(btw_file_path)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165JSON\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_json_btw(data, file_path):<\/p>\n<p>    with open(file_path, &#39;w&#39;) as file:<\/p>\n<p>        json.dump(data, file, indent=4)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_data = {&#39;column1&#39;: [1, 2, 3], &#39;column2&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]}<\/p>\n<p>write_json_btw(new_data, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528yaml\u5e93\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u662fYAML\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528PyYAML\u5e93\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u5b89\u88c5PyYAML<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5PyYAML\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyyaml<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8bfb\u53d6YAML\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import yaml<\/p>\n<p>def read_yaml_btw(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        data = yaml.<a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>_load(file)<\/p>\n<p>    return data<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>data = read_yaml_btw(btw_file_path)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165YAML\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_yaml_btw(data, file_path):<\/p>\n<p>    with open(file_path, &#39;w&#39;) as file:<\/p>\n<p>        yaml.dump(data, file, default_flow_style=False)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_data = {&#39;column1&#39;: [1, 2, 3], &#39;column2&#39;: [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]}<\/p>\n<p>write_yaml_btw(new_data, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u4f7f\u7528xml.etree.ElementTree\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u662fXML\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684xml.etree.ElementTree\u5e93\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6XML\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import xml.etree.ElementTree as ET<\/p>\n<p>def read_xml_btw(file_path):<\/p>\n<p>    tree = ET.parse(file_path)<\/p>\n<p>    root = tree.getroot()<\/p>\n<p>    data = []<\/p>\n<p>    for child in root:<\/p>\n<p>        data.append(child.attrib)<\/p>\n<p>    return data<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>data = read_xml_btw(btw_file_path)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165XML\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_xml_btw(data, file_path):<\/p>\n<p>    root = ET.Element(&#39;root&#39;)<\/p>\n<p>    for item in data:<\/p>\n<p>        child = ET.SubElement(root, &#39;item&#39;)<\/p>\n<p>        for key, value in item.items():<\/p>\n<p>            child.set(key, value)<\/p>\n<p>    tree = ET.ElementTree(root)<\/p>\n<p>    tree.write(file_path)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_data = [{&#39;column1&#39;: &#39;1&#39;, &#39;column2&#39;: &#39;a&#39;}, {&#39;column1&#39;: &#39;2&#39;, &#39;column2&#39;: &#39;b&#39;}, {&#39;column1&#39;: &#39;3&#39;, &#39;column2&#39;: &#39;c&#39;}]<\/p>\n<p>write_xml_btw(new_data, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u4f7f\u7528csv\u5e93\u5904\u7406BTW\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5982\u679cBTW\u6587\u4ef6\u662fCSV\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684csv\u5e93\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>\u8bfb\u53d6CSV\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import csv<\/p>\n<p>def read_csv_btw(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        reader = csv.reader(file)<\/p>\n<p>        data = [row for row in reader]<\/p>\n<p>    return data<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>btw_file_path = &#39;example.btw&#39;<\/p>\n<p>data = read_csv_btw(btw_file_path)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5199\u5165CSV\u683c\u5f0f\u7684BTW\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def write_csv_btw(data, file_path):<\/p>\n<p>    with open(file_path, &#39;w&#39;, newline=&#39;&#39;) as file:<\/p>\n<p>        writer = csv.writer(file)<\/p>\n<p>        writer.writerows(data)<\/p>\n<h2><strong>\u793a\u4f8b\u4f7f\u7528<\/strong><\/h2>\n<p>new_data = [[&#39;column1&#39;, &#39;column2&#39;], [1, &#39;a&#39;], [2, &#39;b&#39;], [3, &#39;c&#39;]]<\/p>\n<p>write_csv_btw(new_data, &#39;new_example.btw&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p><strong>\u4f7f\u7528Python\u7684\u6587\u4ef6\u5904\u7406\u5e93\u3001\u4f7f\u7528\u4e13\u95e8\u7684\u7b2c\u4e09\u65b9\u5e93<\/strong>\u90fd\u662f\u6253\u5f00BTW\u683c\u5f0f\u6587\u4ef6\u7684\u6709\u6548\u65b9\u6cd5\u3002\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u548cBTW\u6587\u4ef6\u7684\u7c7b\u578b\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u5982\u679c\u662fBartender\u683c\u5f0f\u7684BTW\u6587\u4ef6\uff0c\u53ef\u4ee5\u5229\u7528Bartender\u7684API\u6765\u64cd\u4f5c\uff0c\u80fd\u5927\u5927\u7b80\u5316\u4ee3\u7801\u548c\u63d0\u9ad8\u6548\u7387\u3002\u5982\u679c\u662f\u81ea\u5b9a\u4e49\u683c\u5f0f\u7684BTW\u6587\u4ef6\uff0c\u5219\u9700\u8981\u4e86\u89e3\u6587\u4ef6\u7684\u5177\u4f53\u7ed3\u6784\u5e76\u8fdb\u884c\u624b\u52a8\u89e3\u6790\u3002\u65e0\u8bba\u662f\u54ea\u79cd\u65b9\u6cd5\uff0c\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\u90fd\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u5904\u7406BTW\u683c\u5f0f\u6587\u4ef6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6253\u5f00btw\u683c\u5f0f\u7684\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u6253\u5f00btw\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u9996\u5148\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u4e86\u9002\u5f53\u7684\u5e93\u3002btw\u6587\u4ef6\u901a\u5e38\u662fBarTender\u8f6f\u4ef6\u751f\u6210\u7684\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f8\u5e94\u7684\u5e93\u6216API\u6765\u8bfb\u53d6\u548c\u5904\u7406\u8fd9\u4e9b\u6587\u4ef6\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u5229\u7528\u4e13\u95e8\u7684\u5e93\uff0c\u5982pybt, \u8fd9\u53ef\u4ee5\u5e2e\u52a9\u4f60\u89e3\u6790btw\u6587\u4ef6\u5185\u5bb9\u5e76\u8fdb\u884c\u540e\u7eed\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5904\u7406btw\u6587\u4ef6\u65f6\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u5e93\u53ef\u4ee5\u4f7f\u7528\uff1f<\/strong><br \/>\u5904\u7406btw\u6587\u4ef6\u7684\u5e38\u89c1\u5e93\u5305\u62ecpybt\u3001Pandas\u7b49\u3002pybt\u662f\u4e13\u95e8\u7528\u4e8e\u4e0eBarTender\u6587\u4ef6\u4ea4\u4e92\u7684\u5e93\uff0c\u800cPandas\u5219\u53ef\u4ee5\u5728\u9700\u8981\u5c06\u6570\u636e\u8f6c\u6362\u4e3aDataFrame\u683c\u5f0f\u65f6\u6d3e\u4e0a\u7528\u573a\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u9002\u5f53\u7684API\uff0c\u7528\u6237\u53ef\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u6587\u4ef6\u64cd\u4f5c\u548c\u6570\u636e\u63d0\u53d6\u3002<\/p>\n<p><strong>\u6253\u5f00btw\u683c\u5f0f\u6587\u4ef6\u65f6\u53ef\u80fd\u9047\u5230\u54ea\u4e9b\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u6253\u5f00btw\u683c\u5f0f\u6587\u4ef6\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u6587\u4ef6\u635f\u574f\u3001\u7248\u672c\u4e0d\u517c\u5bb9\u7b49\u95ee\u9898\u3002\u5982\u679c\u4f7f\u7528\u7684\u5e93\u4e0d\u652f\u6301\u7279\u5b9a\u7248\u672c\u7684btw\u6587\u4ef6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bfb\u53d6\u5931\u8d25\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u6b63\u786e\uff0c\u4e14\u5177\u6709\u76f8\u5e94\u7684\u6743\u9650\uff0c\u4e5f\u662f\u907f\u514d\u9519\u8bef\u7684\u91cd\u8981\u56e0\u7d20\u3002\u9047\u5230\u95ee\u9898\u65f6\uff0c\u68c0\u67e5\u76f8\u5173\u6587\u6863\u6216\u793e\u533a\u8bba\u575b\u53ef\u80fd\u4f1a\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u6253\u5f00BTW\u683c\u5f0f\u6587\u4ef6\u6709\u51e0\u79cd\u65b9\u6cd5\u3002\u4f7f\u7528Python\u7684\u6587\u4ef6\u5904\u7406\u5e93\u3001\u4f7f\u7528\u4e13\u95e8\u7684\u7b2c\u4e09\u65b9\u5e93\u3002\u5176\u4e2d\uff0c\u4f7f\u7528\u6587\u4ef6 [&hellip;]","protected":false},"author":3,"featured_media":1184782,"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\/1184773"}],"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=1184773"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184773\/revisions"}],"predecessor-version":[{"id":1184783,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1184773\/revisions\/1184783"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1184782"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1184773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1184773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1184773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}