{"id":168764,"date":"2022-04-18T20:09:56","date_gmt":"2022-04-18T12:09:56","guid":{"rendered":"http:\/\/www.idc.net\/help\/168764\/"},"modified":"2022-04-18T20:09:56","modified_gmt":"2022-04-18T12:09:56","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9apython%e6%80%8e%e4%b9%88%e5%ad%98%e5%82%a8%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/168764\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1apython\u600e\u4e48\u5b58\u50a8\u6570\u636e"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/003\/5d6f7de5bfc63918.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5728Python\u5f00\u53d1\u4e2d\uff0c\u6570\u636e\u5b58\u50a8\u3001\u8bfb\u53d6\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u73af\u8282\uff0c\u800c\u4e14\u53ef\u4ee5\u91c7\u7528\u7684\u5b58\u50a8\u65b9\u5f0f\u4e5f\u5f88\u591a\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u6709json\u6587\u4ef6\u3001csv\u6587\u4ef6\u3001MySQL\u6570\u636e\u5e93\u3001Redis\u6570\u636e\u5e93\u4ee5\u53caMongdb\u6570\u636e\u5e93\u7b49\u3002<\/p>\n<p><strong>1. json\u6587\u4ef6\u5b58\u50a8\u6570\u636e<\/strong><\/p>\n<p>json\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u6570\u636e\u4ea4\u6362\u683c\u5f0f\uff0c\u91c7\u7528\u5b8c\u5168\u72ec\u7acb\u4e8e\u7f16\u7a0b\u8bed\u8a00\u7684\u6587\u672c\u683c\u5f0f\u6765\u5b58\u50a8\u548c\u8868\u793a\u6570\u636e\uff0c\u53ef\u4ee5\u8f7b\u677e\u89e3\u51b3py2\u548cpy3\u7684\u7f16\u7801\u95ee\u9898\uff0c\u5185\u5bb9\u7ed3\u6784\u7c7b\u4f3c\u4e8epython\u4e2d\u7684\u5b57\u5178\u548c\u5217\u8868\uff0c\u5c42\u6b21\u7ed3\u6784\u7b80\u6d01\u800c\u6e05\u6670\uff0c\u6613\u4e8e\u4eba\u9605\u8bfb\u548c\u7f16\u5199\uff0c\u540c\u65f6\u4e5f\u6613\u4e8e\u673a\u5668\u89e3\u6790\u548c\u751f\u6210\uff0c\u5e76\u6709\u6548\u5730\u63d0\u5347\u7f51\u7edc\u4f20\u8f93\u6548\u7387\u3002<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a\u300aPython\u6559\u7a0b\u300b<\/p>\n<p><strong>2. csv\u6587\u4ef6<\/strong><\/p>\n<p>Python\u53ef\u4ee5\u5c06\u6570\u636e\u5b58\u50a8\u4e3aCSV\u6587\u4ef6\u683c\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u7528excel\u6253\u5f00CSV\u6587\u6863\uff0c\u8fdb\u884c\u6570\u636e\u7684\u6d4f\u89c8\uff0c\u5341\u5206\u65b9\u4fbf\uff0c\u4ee5\u4e0b\u662f\u5c06\u6570\u636e\u5b58\u50a8\u5230test.csv\u6587\u4ef6\u7684\u76f8\u5173\u5b9e\u4f8b\uff1a<\/p>\n<pre>import&nbsp;pandas&nbsp;as&nbsp;pd\nlist=[[1\uff0c2\uff0c3]\uff0c[4\uff0c5\uff0c6]\uff0c[7\uff0c8\uff0c9]]\nname=[\u2018id\u2019\uff0c\u2019uid\u2019\uff0c\u2019time\u2019]\ntest=pd.DataFrame(columns=name\uff0cdate=list)\ntest.to_csv(\u2018E:\/test.csv\u2019)<\/pre>\n<p><strong>3. MySQL\u6570\u636e\u5e93<\/strong><\/p>\n<p>MySQL\u6570\u636e\u5e93\u5b58\u50a8\u65b9\u5f0f\u662f\u4f7f\u7528Python\u6570\u636e\u5b58\u50a8\u6700\u5e38\u7528\u7684\u5b58\u50a8\u65b9\u5f0f\uff0cPython\u6807\u51c6\u6570\u636e\u5e93\u63a5\u53e3\u4e3aPython DB-API\uff0cPython DB-API\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u4e86\u6570\u636e\u5e93\u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3\uff0cMySQLdb \u662f\u7528\u4e8ePython\u94fe\u63a5Mysql\u6570\u636e\u5e93\u7684\u63a5\u53e3\u3002MySQL\u6570\u636e\u5e93\u5b58\u50a8\u8fc7\u7a0b\u662f\u5f15\u5165API\u6a21\u5757\u3001\u83b7\u53d6\u4e0e\u6570\u636e\u5e93\u7684\u8fde\u63a5\u3001\u6267\u884cSQL\u8bed\u53e5\u548c\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6700\u540e\u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/p>\n<p><strong>4. Redis\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528Python\u6570\u636e\u5b58\u50a8\u4e3aRedis\u6570\u636e\u5e93\uff0c\u4f18\u70b9\u662f\u65b9\u4fbf\u3001\u901f\u5ea6\u5feb\uff0c\u4f46\u662f\u53d6\u51fa\u7684\u6570\u636e\u662f\u4e8c\u8fdb\u5236\u6570\u636e\uff0c\u4e00\u822c\u9700\u8981\u8f6c\u4e3a\u5b57\u7b26\u4e32\u518d\u64cd\u4f5c\uff0c\u4ee5\u4e0b\u662f\u5177\u4f53\u5b9e\u4f8b\uff1a<\/p>\n<pre>import&nbsp;redis\nclient&nbsp;=&nbsp;redis.Redis(host='lcoalhost'\uff0c&nbsp;port=8080)\nclient.set('nums'\uff0c&nbsp;[6\uff0c7\uff0c8\uff0c5\uff0c4])&nbsp;\nresult&nbsp;=&nbsp;client.get('name')&nbsp;\npipe&nbsp;=&nbsp;client.pipeline()&nbsp;\npipe.set('name'\uff0c&nbsp;'oldboy')&nbsp;\npipe.execute()<\/pre>\n<p><strong>5. Mongdb\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528Python\u6570\u636e\u5b58\u50a8\u4e3aMongdb\u6570\u636e\u5e93\uff0c\u4f18\u70b9\u662f\u4e0d\u5728\u4e4e\u6570\u636e\u7ed3\u6784\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\u53d6\u51fa\u6765\u7684\u65f6\u5019\u9700\u8981\u5199\u4e2a\u811a\u672c\u6574\u7406\u4e00\u4e0b\uff0c\u4ee5\u4e0b\u662f\u5177\u4f53\u5b9e\u4f8b\uff1a<\/p>\n<pre>import&nbsp;pymongo\nclient&nbsp;=&nbsp;pymongo.MongoClient('localhost'\uff0c&nbsp;8080)&nbsp;\ntest1_db&nbsp;=&nbsp;client.test1\nsheet_stu&nbsp;=&nbsp;db.stu\ninfo&nbsp;=&nbsp;{name:'oldboy'\uff0cage:30}&nbsp;\ninfo_id&nbsp;=&nbsp;stu.insert_one(info).inserted_id&nbsp;\ncur_list&nbsp;=&nbsp;[cur&nbsp;for&nbsp;cur&nbsp;in&nbsp;stu.find()]&nbsp;\ncount&nbsp;=&nbsp;stu.count()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Python\u5f00\u53d1\u4e2d\uff0c\u6570\u636e\u5b58\u50a8\u3001\u8bfb\u53d6\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u73af\u8282\uff0c\u800c\u4e14\u53ef\u4ee5\u91c7\u7528\u7684\u5b58\u50a8\u65b9\u5f0f\u4e5f\u5f88\u591a\uff0c\u5e38\u7528\u7684\u65b9\u6cd5\u6709json\u6587\u4ef6\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":168765,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-168764","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/168764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=168764"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/168764\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/168765"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=168764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=168764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=168764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}