{"id":216480,"date":"2020-11-21T23:34:19","date_gmt":"2020-11-21T15:34:19","guid":{"rendered":"http:\/\/4563.org\/?p=216480"},"modified":"2020-11-21T23:34:19","modified_gmt":"2020-11-21T15:34:19","slug":"python-%e6%b1%82%e9%97%ae%e6%80%8e%e4%b9%88%e6%94%b9%e5%b5%8c%e5%a5%97-list-%e6%88%96%e8%80%85-tuple-%e9%87%8c%e7%9a%84%e6%9f%90%e4%b8%aa%e5%b1%82%e7%9a%84%e6%9f%90%e4%b8%aa%e5%80%bc%ef%bc%8c%e5%a5%97","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=216480","title":{"rendered":"Python \u6c42\u95ee\u600e\u4e48\u6539\u5d4c\u5957 list \u6216\u8005 tuple \u91cc\u7684\u67d0\u4e2a\u5c42\u7684\u67d0\u4e2a\u503c\uff0c\u5957\u5a03\u662f\u5927\u5751\u554a"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u6c42\u95ee\u600e\u4e48\u6539\u5d4c\u5957 list \u6216\u8005 tuple \u91cc\u7684\u67d0\u4e2a\u5c42\u7684\u67d0\u4e2a\u503c\uff0c\u5957\u5a03\u662f\u5927\u5751\u554a               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : leegradyllljjjj <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e8b\u60c5\u662f\u8fd9\u6837\u7684\uff0c\u6709\u4e00\u4e2a\u5d4c\u5957\u5217\u8868\uff0c\u5217\u8868\u91cc\u5d4c\u5957\u7684\u4e1c\u897f\u7c7b\u578b\u4e0d\u786e\u5b9a\u3002\u6bd4\u5982\uff1a <code>[1,2,3,4,[9,5,6,7]]<\/code> \u4ee5\u53ca <code>[Float(2.423),2,4,2,[],[Float(2.312)]]<\/code> \u8fd8\u6709 <code>(Flaot(2.453),(2.231,9,8,7),1.2234,2.333)<\/code> \u751a\u81f3\u8fd8\u6709(Float(1.222),5.225,&#8221;this is string&#8221;)<\/p>\n<p>\u73b0\u5728\u7684\u95ee\u9898\u662f Float()\u8fd9\u79cd sympy \u91cc\u7684\u7c7b\u578b\u76f4\u63a5\u5e8f\u5217\u5316\u62a5\u9519\uff0c\u6240\u4ee5\u53ea\u6709\u627e\u5230\u8fd9\u4e9b\u7c7b\u578b\u7684\u6570\u636e\u7136\u540e\u5904\u7406\uff0c \u8bf7\u95ee\u6709\u6ca1\u6709\u7b80\u6613\u7684\u529e\u6cd5\u5462\uff1f<\/p>\n<p>1.\u627e\u5230 Float \u7c7b\u578b\u6570\u636e\u5e76\u4f7f\u7528 float()\u66ff\u6362 2. \u4fdd\u6301\u539f\u6765\u7684\u7ed3\u6784 3. \u5904\u7406\u8fc7\u540e\u662f list \u5d4c\u5957\u6216\u8005 tuple \u5d4c\u5957\u90fd\u65e0\u6240\u8c13<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4398087\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : XiaoxiaoPu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u7684\u4ec0\u4e48\u5e8f\u5217\u5316\u65b9\u5f0f\uff1f json \u662f\u652f\u6301\u5bf9\u8c61\u7279\u6b8a\u5904\u7406\u7684\uff0c\u4f60\u662f\u7528\u7684\u5e8f\u5217\u5316\u65b9\u5f0f\u53ef\u80fd\u4e5f\u6709\u54cd\u5e94\u7684\u652f\u6301                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4398088\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : leegradyllljjjj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             simplejson.dumps(data),\u91cc\u9762\u7684 Float \u7279\u6b8a\u7c7b\u578b\u5c31\u62a5\u9519\uff0c\u53ea\u597d\u8f6c\u6362\u6210 python \u57fa\u672c\u7c7b\u578b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4398089\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SaltCat <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f7f\u7528 json.dumps \u7684 default \u53c2\u6570:<\/p>\n<p>&#8220;`<br \/>json.dumps(sth, default=lambda x: x.toNative() if isinstance(x, MyCustomFloat) else None)<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4398090\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SaltCat <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u597d\u4e45\u90fd\u4e0d\u7528\u76f4\u63a5 json \u5e8f\u5217\u5316\u4e86, \u4e0a\u6b21\u7528\u662f custom FastAPI \u7684 Response, \u81ea\u5df1\u9020\u4e86\u4e2a OrjsonResponse(\u540e\u9762\u5b98\u65b9\u63d0\u4f9b\u4e86), \u5c31\u7528\u4e86 singledispacherxxxxx \u548c\u8fd9\u4e2a\u7279\u6027.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u6c42\u95ee\u600e\u4e48\u6539\u5d4c\u5957 li&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/216480"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216480"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/216480\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216480"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}