{"id":125650,"date":"2020-06-26T03:27:24","date_gmt":"2020-06-25T19:27:24","guid":{"rendered":"http:\/\/4563.org\/?p=125650"},"modified":"2020-06-26T03:27:24","modified_gmt":"2020-06-25T19:27:24","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%b8%a4%e4%b8%aa%e5%ad%97%e5%85%b8%e5%af%b9%e6%af%94%ef%bc%8c%e7%bb%93%e6%9e%9c%e5%92%8c%e6%83%b3%e8%b1%a1%e7%9a%84%e4%b8%8d%e5%90%8c%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=125650","title":{"rendered":"\u4e3a\u4ec0\u4e48\u4e24\u4e2a\u5b57\u5178\u5bf9\u6bd4\uff0c\u7ed3\u679c\u548c\u60f3\u8c61\u7684\u4e0d\u540c\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e3a\u4ec0\u4e48\u4e24\u4e2a\u5b57\u5178\u5bf9\u6bd4\uff0c\u7ed3\u679c\u548c\u60f3\u8c61\u7684\u4e0d\u540c\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qazwsxkevin <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>*** import decimal from sqlalchemy import Integer,Numeric,String,INTEGER,DateTime,DECIMAL,null ***  if __name__ == '__main__':        a = {'\u65f6\u95f4': datetime.datetime(2020, 5, 10, 11, 19), '\u529b\u91cf': DECIMAL('26.77'), '\u91cf\u503c': 90, '\u53d8\u5316': None, '\u5c5e\u6027': None,          '\u5bf9\u65b9\u529b\u91cf': DECIMAL('31.75'), 'TOP': 2291, '\u6700\u4f4e\u529b\u91cf': DECIMAL('1.89'), '\u6700\u9ad8\u529b\u91cf': 2022, 'roundid': '899',          '\u5e8f\u53f7': 1}     b = {'\u65f6\u95f4': datetime.datetime(2020, 5, 10, 11, 25), '\u529b\u91cf': DECIMAL('26.77'), '\u91cf\u503c': 90, '\u53d8\u5316': None, '\u5c5e\u6027': None,          '\u5bf9\u65b9\u529b\u91cf': DECIMAL('31.75'), 'TOP': 2291, '\u6700\u4f4e\u529b\u91cf': DECIMAL('1.89'), '\u6700\u9ad8\u529b\u91cf': 2022, 'roundid': '899',          '\u5e8f\u53f7': 2}      a.pop('\u5e8f\u53f7')     a.pop('\u65f6\u95f4')      b.pop('\u5e8f\u53f7')     b.pop('\u65f6\u95f4')       if a == b:         print('\u76f8\u540c')     else:         print('\u4e0d\u540c')      # \u8fd9\u91cc\u5bf9\u6bd4\u7ed3\u679c\u662f False\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u540c\uff1f   \u6000\u7591\u662f DECIMAL \u7684\u95ee\u9898\uff1f\u6211\u7ee7\u7eed\u505a\u4e86\u4e0b\u9762\u7684\u6d4b\u8bd5      a = decimal.Decimal('1.77')     b = decimal.Decimal('1.77')      if a == b:         print('yes')     else:         print('no')      if a == b:         print('True')     else:         print('False')       # \u8fd9\u91cc\u662f True....       a = DECIMAL('1.77')     b = DECIMAL('1.77')      if a == b:         print('yes')     else:         print('no')      # \u8fd9\u91cc\u662f False  <\/code><\/pre>\n<pre><code>a \u548c b\uff0c\u5176\u5b9e\u662f\u5728\u4e00\u4e2a\u5217\u8868\u91cc\uff0c\u5305\u542b N \u4e2a\u5b57\u5178\uff0c\u5386\u904d\u83b7\u53d6\uff0c\u662f\u51c6\u5907\u901a\u8fc7 sqlalchemy \u5199\u5165\u5230 mysql\uff0c a \u548c b\uff0cpop \u4e86\u5e8f\u53f7\u548c\u65f6\u95f4\u4e24\u4e2a\u5143\u7d20\u540e\uff0c\u5185\u5bb9\u80af\u5b9a\u662f\u4e00\u6837\u7684, \u8bf7\u6559\u5404\u4f4d\u9ad8\u624b\uff0ca.b \u5bf9\u6bd4\u51fa\u4e86\u4ec0\u4e48\u95ee\u9898\uff1f <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2158238\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wuwukai007 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             def __eq__(self,obj):<br \/>&gt;&gt;&gt;&gt;if self.precision == obj.precision:<br \/>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;return True<br \/>&gt;&gt;&gt;&gt;else:<br \/>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;return False<br \/>DECIMAL.__eq__ = __eq__<br \/>a == b = True                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158239\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lithbitren <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b57\u5178\u91cc\u7528\u5185\u7f6e\u5e93\u7684 decimal.Decimal \u6bd4\u662f\u76f8\u540c\u7684\uff0c\u518d\u6392\u67e5\u4e0b\u662f\u4e0d\u662f sqlalchemy \u6a21\u5757\u7684\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158240\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : qazwsxkevin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u8c22\u8c22\u4e24\u4f4d\uff0c\u4f9d\u7136\u4e0d\u662f\u660e\u767d\u539f\u56e0\uff0c\u60f3\u4e86\u4e00\u665a\uff0c\u770b\u6837\u5b50\u50cf\u662f\u8981\u628a a,b \u4e24\u4e2a\u5b57\u5178\u91cc\u9762\uff0c\u662f DECIMAL \u7c7b\u578b\u7684\u5143\u7d20\uff0c\u8f6c\u6210 deciaml.Decimal \u540e\uff0c\u518d\u53bb\u505a\u6bd4\u8f83\uff0c\u5b57\u5178\u6570\u91cf\u4e0d\u5c11\uff0c\u6709\u4e9b\u62c5\u5fc3\u6548\u7387\u4e25\u91cd\u6162\u4e86\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158241\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuanbg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ab = decimal.Decimal(&#8216;1.77&#8217;)\u65f6\uff0ca \u548c b \u6bd4\u7684\u662f\u503c\u3002<br \/>ab = DECIMAL(&#8216;1.77&#8217;)\u65f6\uff0ca \u548c b \u6bd4\u7684\u662f\u5bf9\u8c61\uff0cab \u662f\u5b57\u5178\u7684\u65f6\u5019\u6bd4\u7684\u4e5f\u662f\u5bf9\u8c61\u3002\u4e24\u4e2a\u4e0d\u540c\u7684\u5bf9\u8c61\u5f53\u7136\u4e0d\u76f8\u7b49\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158242\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : toaruScar <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u770b\u8fc7 sqlalchemy.DECIMAL \u7684\u6587\u6863\u4e86\u5417\uff1f <br \/>DECIMAL \u662f\u7528\u6765\u8868\u793a\u6570\u636e\u7c7b\u578b\u7684\uff0c\u4f60\u662f\u4e0d\u662f\u770b\u7740\u540d\u5b57\u5dee\u4e0d\u591a\u5c31\u6253\u7b97\u5927\u529b\u51fa\u5947\u8ff9\u4e86\uff1f<br \/>\u662f\u4e0d\u662f\u8fd8\u6253\u7b97\u7528 sqlalchemy.String \u6765\u5b58 str \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158243\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iceking <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &gt;&gt;&gt; class foo():<br \/>&#8230; pass<br \/>&#8230; <br \/>&gt;&gt;&gt; a = foo()<br \/>&gt;&gt;&gt; b = foo()<br \/>&gt;&gt;&gt; a == b<br \/>False<\/p>\n<p>object \u7684 __eq__ \u65b9\u6cd5\u6bd4\u8f83\u7684\u4e24\u4e2a\u5bf9\u8c61\u7684 id \u3002\u53ef\u4ee5\u901a\u8fc7\u81ea\u5df1\u5b9e\u73b0 __eq__ \u6765\u6bd4\u8f83\u503c\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158244\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iceking <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xuanbg \u5b57\u5178\u6bd4\u8f83\u7684\u662f\u503c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158245\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SjwNo1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u9700\u8981\u770b sqlalchemy.DECIMAL                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2158246\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : SjwNo1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6216\u8005\u4f60\u53ef\u4ee5\u91cd\u5199 __eq__<br \/>DECIMAL \u4e00\u822c\u7528\u6765\u58f0\u660e\u5b57\u6bb5\u7c7b\u578b\uff0c \u6e90\u7801\u5185\u90e8\u6709\u4e00\u4e2a comparator_factory \u53ef\u80fd\u5bf9\u4f60\u6709\u5e2e\u52a9                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u4e24\u4e2a\u5b57\u5178\u5bf9\u6bd4\uff0c\u7ed3\u679c\u548c\u60f3\u8c61\u7684\u4e0d&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\/125650"}],"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=125650"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/125650\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125650"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}