{"id":1080868,"date":"2025-01-08T12:34:11","date_gmt":"2025-01-08T04:34:11","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1080868.html"},"modified":"2025-01-08T12:34:15","modified_gmt":"2025-01-08T04:34:15","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e5%8f%98%e9%87%8f%e4%bf%9d%e5%ad%98%e4%b8%8b%e6%9d%a5python-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1080868.html","title":{"rendered":"\u5982\u4f55\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e0b\u6765python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183201\/2970e8d0-3a27-4be8-abe5-c1f5ba6432ca.webp\" alt=\"\u5982\u4f55\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e0b\u6765python\" \/><\/p>\n<p><p> <strong>\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e0b\u6765\u5728Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6587\u4ef6I\/O\u3001\u4f7f\u7528pickle\u6a21\u5757\u3001\u4f7f\u7528json\u6a21\u5757<\/strong>\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528pickle\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><p>pickle\u6a21\u5757\u53ef\u4ee5\u5c06Python\u5bf9\u8c61\u5e8f\u5217\u5316\u540e\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4e4b\u540e\u53ef\u4ee5\u53cd\u5e8f\u5217\u5316\u6062\u590d\u5bf9\u8c61\u3002\u4f7f\u7528pickle\u6a21\u5757\u7684\u4f18\u70b9\u662f\u80fd\u591f\u4fdd\u5b58\u51e0\u4e4e\u6240\u6709\u7c7b\u578b\u7684Python\u5bf9\u8c61\uff0c\u5305\u62ec\u81ea\u5b9a\u4e49\u7c7b\u7684\u5b9e\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u6587\u4ef6I\/O\u4fdd\u5b58\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u6587\u4ef6I\/O\u4fdd\u5b58\u53d8\u91cf\u662f\u6700\u57fa\u672c\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6\u6216\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u6587\u672c\u6587\u4ef6\u9002\u7528\u4e8e\u4fdd\u5b58\u5b57\u7b26\u4e32\u548c\u7b80\u5355\u7684\u6570\u636e\u7ed3\u6784\uff0c\u800c\u4e8c\u8fdb\u5236\u6587\u4ef6\u9002\u7528\u4e8e\u4fdd\u5b58\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4fdd\u5b58\u4e3a\u6587\u672c\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u53d8\u91cf\u4e3a\u6587\u672c\u6587\u4ef6<\/p>\n<p>data = &quot;Hello, world!&quot;<\/p>\n<p>with open(&quot;data.txt&quot;, &quot;w&quot;) as file:<\/p>\n<p>    file.write(data)<\/p>\n<h2><strong>\u4ece\u6587\u672c\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>with open(&quot;data.txt&quot;, &quot;r&quot;) as file:<\/p>\n<p>    data = file.read()<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4fdd\u5b58\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u53d8\u91cf\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6<\/p>\n<p>data = b&quot;Hello, world!&quot;<\/p>\n<p>with open(&quot;data.bin&quot;, &quot;wb&quot;) as file:<\/p>\n<p>    file.write(data)<\/p>\n<h2><strong>\u4ece\u4e8c\u8fdb\u5236\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>with open(&quot;data.bin&quot;, &quot;rb&quot;) as file:<\/p>\n<p>    data = file.read()<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528pickle\u6a21\u5757\u4fdd\u5b58\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>pickle\u6a21\u5757\u53ef\u4ee5\u5c06Python\u5bf9\u8c61\u5e8f\u5217\u5316\u540e\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4e4b\u540e\u53ef\u4ee5\u53cd\u5e8f\u5217\u5316\u6062\u590d\u5bf9\u8c61\u3002pickle\u6a21\u5757\u652f\u6301\u591a\u79cdPython\u5bf9\u8c61\u7c7b\u578b\uff0c\u5305\u62ec\u5217\u8868\u3001\u5b57\u5178\u3001\u81ea\u5b9a\u4e49\u7c7b\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4fdd\u5b58\u53d8\u91cf\u4e3apickle\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pickle<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3apickle\u6587\u4ef6<\/strong><\/h2>\n<p>data = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>with open(&quot;data.pkl&quot;, &quot;wb&quot;) as file:<\/p>\n<p>    pickle.dump(data, file)<\/p>\n<h2><strong>\u4ecepickle\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>with open(&quot;data.pkl&quot;, &quot;rb&quot;) as file:<\/p>\n<p>    data = pickle.load(file)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4fdd\u5b58\u591a\u4e2a\u53d8\u91cf\u4e3apickle\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import pickle<\/p>\n<h2><strong>\u4fdd\u5b58\u591a\u4e2a\u53d8\u91cf\u4e3apickle\u6587\u4ef6<\/strong><\/h2>\n<p>data1 = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>data2 = [1, 2, 3, 4, 5]<\/p>\n<p>with open(&quot;data.pkl&quot;, &quot;wb&quot;) as file:<\/p>\n<p>    pickle.dump((data1, data2), file)<\/p>\n<h2><strong>\u4ecepickle\u6587\u4ef6\u8bfb\u53d6\u591a\u4e2a\u53d8\u91cf<\/strong><\/h2>\n<p>with open(&quot;data.pkl&quot;, &quot;rb&quot;) as file:<\/p>\n<p>    data1, data2 = pickle.load(file)<\/p>\n<p>print(data1)<\/p>\n<p>print(data2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528json\u6a21\u5757\u4fdd\u5b58\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>json\u6a21\u5757\u53ef\u4ee5\u5c06Python\u5bf9\u8c61\u5e8f\u5217\u5316\u4e3aJSON\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u4e4b\u540e\u53ef\u4ee5\u53cd\u5e8f\u5217\u5316\u6062\u590d\u5bf9\u8c61\u3002json\u6a21\u5757\u9002\u7528\u4e8e\u4fdd\u5b58\u7b80\u5355\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5982\u5b57\u5178\u548c\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4fdd\u5b58\u53d8\u91cf\u4e3aJSON\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3aJSON\u6587\u4ef6<\/strong><\/h2>\n<p>data = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>with open(&quot;data.json&quot;, &quot;w&quot;) as file:<\/p>\n<p>    json.dump(data, file)<\/p>\n<h2><strong>\u4eceJSON\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>with open(&quot;data.json&quot;, &quot;r&quot;) as file:<\/p>\n<p>    data = json.load(file)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4fdd\u5b58\u591a\u4e2a\u53d8\u91cf\u4e3aJSON\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import json<\/p>\n<h2><strong>\u4fdd\u5b58\u591a\u4e2a\u53d8\u91cf\u4e3aJSON\u6587\u4ef6<\/strong><\/h2>\n<p>data1 = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>data2 = [1, 2, 3, 4, 5]<\/p>\n<p>with open(&quot;data.json&quot;, &quot;w&quot;) as file:<\/p>\n<p>    json.dump({&quot;data1&quot;: data1, &quot;data2&quot;: data2}, file)<\/p>\n<h2><strong>\u4eceJSON\u6587\u4ef6\u8bfb\u53d6\u591a\u4e2a\u53d8\u91cf<\/strong><\/h2>\n<p>with open(&quot;data.json&quot;, &quot;r&quot;) as file:<\/p>\n<p>    data = json.load(file)<\/p>\n<p>data1 = data[&quot;data1&quot;]<\/p>\n<p>data2 = data[&quot;data2&quot;]<\/p>\n<p>print(data1)<\/p>\n<p>print(data2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528shelve\u6a21\u5757\u4fdd\u5b58\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>shelve\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u6301\u4e45\u5316\u5b58\u50a8\u673a\u5236\uff0c\u7c7b\u4f3c\u4e8e\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u5c06Python\u5bf9\u8c61\u4fdd\u5b58\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7\u952e\u503c\u5bf9\u7684\u65b9\u5f0f\u8bbf\u95ee\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4fdd\u5b58\u53d8\u91cf\u4e3ashelve\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import shelve<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3ashelve\u6587\u4ef6<\/strong><\/h2>\n<p>data = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>with shelve.open(&quot;data.shelve&quot;) as db:<\/p>\n<p>    db[&quot;data&quot;] = data<\/p>\n<h2><strong>\u4eceshelve\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>with shelve.open(&quot;data.shelve&quot;) as db:<\/p>\n<p>    data = db[&quot;data&quot;]<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4fdd\u5b58\u591a\u4e2a\u53d8\u91cf\u4e3ashelve\u6587\u4ef6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import shelve<\/p>\n<h2><strong>\u4fdd\u5b58\u591a\u4e2a\u53d8\u91cf\u4e3ashelve\u6587\u4ef6<\/strong><\/h2>\n<p>data1 = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>data2 = [1, 2, 3, 4, 5]<\/p>\n<p>with shelve.open(&quot;data.shelve&quot;) as db:<\/p>\n<p>    db[&quot;data1&quot;] = data1<\/p>\n<p>    db[&quot;data2&quot;] = data2<\/p>\n<h2><strong>\u4eceshelve\u6587\u4ef6\u8bfb\u53d6\u591a\u4e2a\u53d8\u91cf<\/strong><\/h2>\n<p>with shelve.open(&quot;data.shelve&quot;) as db:<\/p>\n<p>    data1 = db[&quot;data1&quot;]<\/p>\n<p>    data2 = db[&quot;data2&quot;]<\/p>\n<p>print(data1)<\/p>\n<p>print(data2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u4fdd\u5b58\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u6807\u51c6\u5e93\u4e2d\u7684\u6a21\u5757\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\u53ef\u4ee5\u7528\u6765\u4fdd\u5b58\u548c\u52a0\u8f7d\u53d8\u91cf\uff0c\u5982h5py\u3001joblib\u3001numpy\u7b49\u3002\u8fd9\u4e9b\u5e93\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u548c\u66f4\u7075\u6d3b\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u548c\u79d1\u5b66\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528h5py\u4fdd\u5b58\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>h5py\u5e93\u53ef\u4ee5\u5c06Python\u5bf9\u8c61\u4fdd\u5b58\u4e3aHDF5\u6587\u4ef6\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u548c\u79d1\u5b66\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import h5py<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3aHDF5\u6587\u4ef6<\/strong><\/h2>\n<p>data = np.array([1, 2, 3, 4, 5])<\/p>\n<p>with h5py.File(&quot;data.h5&quot;, &quot;w&quot;) as file:<\/p>\n<p>    file.create_dataset(&quot;data&quot;, data=data)<\/p>\n<h2><strong>\u4eceHDF5\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>with h5py.File(&quot;data.h5&quot;, &quot;r&quot;) as file:<\/p>\n<p>    data = file[&quot;data&quot;][:]<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528joblib\u4fdd\u5b58\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>joblib\u5e93\u53ef\u4ee5\u5c06Python\u5bf9\u8c61\u4fdd\u5b58\u4e3a\u538b\u7f29\u6587\u4ef6\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import joblib<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3ajoblib\u6587\u4ef6<\/strong><\/h2>\n<p>data = {&quot;name&quot;: &quot;Alice&quot;, &quot;age&quot;: 25, &quot;city&quot;: &quot;New York&quot;}<\/p>\n<p>joblib.dump(data, &quot;data.joblib&quot;)<\/p>\n<h2><strong>\u4ecejoblib\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>data = joblib.load(&quot;data.joblib&quot;)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528numpy\u4fdd\u5b58\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>numpy\u5e93\u53ef\u4ee5\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6\u6216\u6587\u672c\u6587\u4ef6\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u7ec4\u548c\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6<\/strong><\/h2>\n<p>data = np.array([1, 2, 3, 4, 5])<\/p>\n<p>np.save(&quot;data.npy&quot;, data)<\/p>\n<h2><strong>\u4ece\u4e8c\u8fdb\u5236\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>data = np.load(&quot;data.npy&quot;)<\/p>\n<p>print(data)<\/p>\n<h2><strong>\u4fdd\u5b58\u53d8\u91cf\u4e3a\u6587\u672c\u6587\u4ef6<\/strong><\/h2>\n<p>np.savetxt(&quot;data.txt&quot;, data)<\/p>\n<h2><strong>\u4ece\u6587\u672c\u6587\u4ef6\u8bfb\u53d6\u53d8\u91cf<\/strong><\/h2>\n<p>data = np.loadtxt(&quot;data.txt&quot;)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e0b\u6765\uff0c\u5305\u62ec\u4f7f\u7528\u6587\u4ef6I\/O\u3001\u4f7f\u7528pickle\u6a21\u5757\u3001\u4f7f\u7528json\u6a21\u5757\u3001\u4f7f\u7528shelve\u6a21\u5757\u4ee5\u53ca\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u548c\u5e94\u7528\u573a\u666f\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u901a\u8fc7\u4e0a\u8ff0\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86\u5982\u4f55\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e0b\u6765\u5e76\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e3a\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u5f0f\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e3a\u6587\u4ef6\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u7684<code>pickle<\/code>\u6a21\u5757\u3001<code>json<\/code>\u6a21\u5757\u6216\u4f7f\u7528<code>numpy<\/code>\u5e93\u3002<code>pickle<\/code>\u53ef\u4ee5\u5e8f\u5217\u5316\u51e0\u4e4e\u6240\u6709\u7684Python\u5bf9\u8c61\uff0c\u800c<code>json<\/code>\u9002\u5408\u4fdd\u5b58\u5b57\u5178\u3001\u5217\u8868\u7b49\u6570\u636e\u7ed3\u6784\u3002\u4f7f\u7528<code>numpy<\/code>\u65f6\uff0c\u901a\u5e38\u7528\u4e8e\u4fdd\u5b58\u6570\u7ec4\u6570\u636e\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7c7b\u578b\u548c\u540e\u7eed\u4f7f\u7528\u7684\u9700\u6c42\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6\u4fdd\u5b58\u7684\u53d8\u91cf\uff1f<\/strong><br \/>\u8bfb\u53d6\u4fdd\u5b58\u7684\u53d8\u91cf\u901a\u5e38\u4e0e\u4fdd\u5b58\u65f6\u4f7f\u7528\u7684\u6a21\u5757\u76f8\u5bf9\u5e94\u3002\u5bf9\u4e8e\u4f7f\u7528<code>pickle<\/code>\u4fdd\u5b58\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pickle.load()<\/code>\u51fd\u6570\u6765\u8bfb\u53d6\u3002\u5bf9\u4e8e<code>json<\/code>\u683c\u5f0f\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>json.load()<\/code>\u51fd\u6570\u3002\u786e\u4fdd\u5728\u8bfb\u53d6\u65f6\u4f7f\u7528\u76f8\u540c\u7684\u683c\u5f0f\u548c\u65b9\u6cd5\uff0c\u786e\u4fdd\u6570\u636e\u7684\u6b63\u786e\u89e3\u7801\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u4fdd\u5b58\u7684\u53d8\u91cf\u6570\u636e\u7684\u5b89\u5168\u6027\u548c\u5b8c\u6574\u6027\uff1f<\/strong><br \/>\u4fdd\u5b58\u53d8\u91cf\u65f6\uff0c\u786e\u4fdd\u6570\u636e\u7684\u5b89\u5168\u6027\u548c\u5b8c\u6574\u6027\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u53ef\u4ee5\u4f7f\u7528\u52a0\u5bc6\u6280\u672f\u5bf9\u6570\u636e\u8fdb\u884c\u52a0\u5bc6\u4fdd\u5b58\u3002\u5176\u6b21\uff0c\u5728\u4fdd\u5b58\u548c\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u8fdb\u884c\u6821\u9a8c\u548c\uff08checksum\uff09\u64cd\u4f5c\uff0c\u4ee5\u786e\u4fdd\u6570\u636e\u5728\u4f20\u8f93\u548c\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u672a\u88ab\u7be1\u6539\u3002\u5b9a\u671f\u5907\u4efd\u4e5f\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u6b65\u9aa4\uff0c\u53ef\u4ee5\u9632\u6b62\u610f\u5916\u4e22\u5931\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5c06\u53d8\u91cf\u4fdd\u5b58\u4e0b\u6765\u5728Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6587\u4ef6I\/O\u3001\u4f7f\u7528pickle\u6a21\u5757\u3001\u4f7f\u7528json\u6a21\u5757\u3002\u4e0b\u9762\u6211 [&hellip;]","protected":false},"author":3,"featured_media":1080883,"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\/1080868"}],"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=1080868"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1080868\/revisions"}],"predecessor-version":[{"id":1080884,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1080868\/revisions\/1080884"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1080883"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1080868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1080868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1080868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}