{"id":152029,"date":"2020-09-02T11:51:56","date_gmt":"2020-09-02T03:51:56","guid":{"rendered":"http:\/\/4563.org\/?p=152029"},"modified":"2020-09-02T11:51:56","modified_gmt":"2020-09-02T03:51:56","slug":"python2-%e4%b8%8e-python3-%e4%b8%ad-struct-%e6%a8%a1%e5%9d%97%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=152029","title":{"rendered":"python2 \u4e0e python3 \u4e2d struct \u6a21\u5757\u7684\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  python2 \u4e0e python3 \u4e2d struct \u6a21\u5757\u7684\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : taomujian <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>import struct test = 18446735964955840608 result = struct.pack(&#8216;&lt;Q&#8217;, test) print(result)<\/p>\n<p>\u4e0a\u9762\u8fd9\u6bb5\u4ee3\u7801\u7528 python2 \u548c python3 \u6267\u884c\u7ed3\u679c\u4e0d\u4e00\u6837,python2 \u6267\u884c\u7684\u7ed3\u679c\u662f\u5b57\u7b26\u4e32,python3 \u6267\u884c\u7684\u7ed3\u679c\u662f\u5b57\u8282\u7801,\u600e\u4e48\u628a python3 \u6267\u884c\u7ed3\u679c\u8f6c\u6362\u6210\u5b57\u7b26\u4e32,\u7b80\u5355\u7684\u8fdb\u884c str \u8f6c\u6362,\u7a0b\u5e8f\u4f1a\u62a5\u9519&#8230;.<\/p>\n<p>\u5728\u7ebf\u7b49\u5404\u4f4d\u5927\u4f6c\u4eec\u6307\u70b9<\/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=\"3180547\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : todd7zhang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             struct.pack \u51fa\u6765\u7684\u672c\u6765\u5c31\u5e94\u8be5\u662f\u5b57\u8282\u7801\uff0c\u8fd8\u60f3\u8981\u66ff\u6362\u4ec0\u4e48\uff0c\u76f4\u63a5\u8bf4\u4f60\u7684\u521d\u59cb\u9700\u6c42\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3180548\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : linw1995 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             py2 \u4e0e py3 \u6700\u5927\u7684\u4e0d\u540c\u5c31\u662f py3 \u4ee5 unicode \u4f5c\u4e3a\u9ed8\u8ba4\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u3002\u8fd9\u6837\u5728 py2 \u4e2d\u5b57\u7b26\u4e32\u5728 py3 \u4e2d\u76f8\u5f53\u4e8e bytes \u5373 b&#8221;&#8230;&#8221;\uff0c\u800c py3 \u4e2d\u7684\u5b57\u7b26\u4e32\u5c31\u76f8\u5f53\u4e8e py2 \u7684 unicode \u5b57\u7b26\u4e32\u5373 u&#8221;&#8230;&#8221;\u3002\u6240\u4ee5 py2 \u7684\u8fd0\u884c\u7ed3\u679c\u4e0e py3 \u7684\u76f8\u540c\uff0c\u5e76\u4e0d\u662f\u4e3b\u8bf4\u7684\u90a3\u6837\uff0c\u8fd0\u884c\u7ed3\u679c\u4e0d\u540c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3180549\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : taomujian <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u9700\u8981\u628a\u4e00\u4e2a\u811a\u672c\u4ece py2 \u6539\u6210 py3,\u6211\u7528 wireshark \u6293\u5305\u540e\u53d1\u73b0\u53d1\u9001\u7684\u6570\u636e\u5305\u4e2d\u6709\u4e00\u6bb5\u5b57\u7b26\u662f b&#8221;\u5f00\u5934\u7684\u5b57\u7b26\u4e32,\u6240\u4ee5\u60f3\u628a b&#8221;\u5f00\u5934\u7684\u7ed9\u6362\u6210\u5b57\u7b26\u4e32,\u521a\u624d\u6211\u6362\u4e86\u4e0b\u601d\u8def\u53d1\u9001\u7684\u6570\u636e\u90fd\u6362\u6210 bytes \u5c31\u597d\u4e86,\u611f\u8c22 2 \u4f4d\u7684\u56de\u590d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3180550\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ruanimal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @taomujian \u9a9a\u5e74\uff0c\u53bb\u4e86\u89e3\u4e0b\u5b57\u7b26\u4e32\u7f16\u7801\u548c unicode \u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>python2 \u4e0e python3&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\/152029"}],"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=152029"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/152029\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152029"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}