{"id":211,"date":"2020-02-29T15:01:31","date_gmt":"2020-02-29T07:01:31","guid":{"rendered":"http:\/\/118.25.47.203\/?page_id=211"},"modified":"2025-07-18T18:37:01","modified_gmt":"2025-07-18T10:37:01","slug":"python","status":"publish","type":"page","link":"https:\/\/blog.ywdevops.cn\/index.php\/python\/","title":{"rendered":"python\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">pip  installl  wxpython -i   https:<em>\/\/pypi.doubanio.com\/simple<\/em>     \/\/\u8868\u793a\u901a\u8fc7pip\u5b89\u88c5wxpython \u5e76\u4e14\u4f7f\u7528\u56fd\u5185\u7684\u8c46\u74e3\u6e90<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u963f\u91cc\u6e90\uff1ahttp:\/\/mirrors.aliyun.com\/pypi\/simple\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6e05\u534e\u5927\u5b66\u6e90\uff1ahttps:\/\/pypi.tuna.tsinghua.edu.cn\/simple<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>json.load(var)\uff1a\u5c06json\u6570\u636e\u8f6c\u5316\u4e3a\u5b57\u5178 (var\u8868\u793ajson\u6570\u636e)<\/li>\n\n\n\n<li>json.dumps(var)\uff1a\u5c06\u5b57\u5178\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32(var\u8868\u793a\u5b57\u5178)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6807\u51c6\u5e93\u67e5\u8be2\u5730\u5740\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:\/\/docs.python.org\/zh-cn\/3.6\/library\/datetime.html  #\u5b98\u65b93.6\u6587\u6863\uff0c\u53ef\u9009\u5176\u4ed6\u7248\u672c\nhttps:\/\/pypi.org\/                                        #Python\u793e\u533a\u5b58\u50a8\u5e93\u5730\u5740<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001<strong>\u670d\u52a1\u5668\u65f6\u95f4\u83b7\u53d6<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import datetime         #\u5bfc\u5165datetime\u6a21\u5757\nprint((datetime.datetime.now()-datetime.timedelta(days=1)).strftime(\"%Y-%m-%d %H:%M\"))      #\u83b7\u53d6\u4e00\u5929\u4e4b\u524d\u7684\u65f6\u95f4\uff0c\u7528strftime\u6765\u683c\u5f0f\u5316\u5230\u5206\u949f,\u4e00\u822c\u4e0d\u683c\u5f0f\u5316\u5230\u79d2\uff0c\u5982\u679c\u8981\u683c\u5f0f\u5316\u5230\u79d2\uff0c\u5c31\u5199\u6210\"%Y-%m-%d %H:%M:%S\"\nprint ((datetime.datetime.now()-datetime.timedelta(minutes=1)).strftime(\"%Y-%m-%d %H:%M\"))   #\u83b7\u53d6\u4e00\u5206\u949f\u4e4b\u524d\u7684\u65f6\u95f4\nprint ((datetime.datetime.now()-datetime.timedelta(hours=10)).strftime(\"%Y-%m-%d %H:%M\"))   #\u83b7\u53d610\u4e2a\u5c0f\u65f6\u4e4b\u524d\u7684\u65f6\u95f4\nprint ((datetime.datetime.now()-datetime.timedelta(seconds=10)).strftime(\"%Y-%m-%d %H:%M\"))  #\u83b7\u53d610s\u4e4b\u524d\u7684\u65f6\u95f4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001<strong>\u5c06\u65f6\u95f4\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u65f6\u95f4\u6233\u7684\u5b9a\u4e49\u662f\uff0c\u4e00\u4e2a\u80fd\u8868\u793a\u4e00\u4efd\u6570\u636e\u5728\u67d0\u4e2a\u7279\u5b9a\u65f6\u95f4\u4e4b\u524d\u5df2\u7ecf\u5b58\u5728\u7684\u3001\u5b8c\u6574\u7684\u3001\u53ef\u9a8c\u8bc1\u7684\u6570\u636e,\u901a\u5e38\u662f\u4e00\u4e2a\u5b57\u7b26\u5e8f\u5217\uff0c\u552f\u4e00\u5730\u6807\u8bc6\u67d0\u4e00\u523b\u7684\u65f6\u95f4\u3002\n\u5728python\u4e2d\uff0c\u65f6\u95f4\u6233\u662f\u4e00\u4e32\u6570\u5b57\uff0c\u5f53\u6211\u4eec\u8981\u628a\u5b83\u8f6c\u6362\u4e3a\u5177\u6709\u4e00\u5b9a\u683c\u5f0f\u7684\u65f6\u95f4\u6570\u636e\u5982 \u20182018-08-08 11:11:11\u2019 \u65f6\uff0c\u9700\u8981\u7528\u5230time\u6a21\u5757\u3002\u540c\u6837\uff0c\u65f6\u95f4\u6570\u636e\u4e5f\u53ef\u4ee5\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\u3002\u5c06\u65f6\u95f4\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\u7684\u5177\u4f53\u6b65\u9aa4\u4e3a\uff1a\n1\u3001\u5229\u7528strptime()\u51fd\u6570\u5c06\u65f6\u95f4\u8f6c\u6362\u6210\u65f6\u95f4\u6570\u7ec4\n2\u3001\u5229\u7528mktime()\u51fd\u6570\u5c06\u65f6\u95f4\u6570\u7ec4\u8f6c\u6362\u6210\u65f6\u95f4\u6233<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"564\" height=\"172\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/dd57b642f09543f7b485051a5fb23ecd.png\" alt=\"\" class=\"wp-image-4013\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/dd57b642f09543f7b485051a5fb23ecd.png 564w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/dd57b642f09543f7b485051a5fb23ecd-300x91.png 300w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"> 3\u3001<strong>\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65f6\u95f4 <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5728\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u65f6\u95f4\u4e2d\uff0c\u9996\u5148\u9700\u8981\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210localtime\uff0c\u518d\u8f6c\u6362\u6210\u65f6\u95f4\u7684\u5177\u4f53\u683c\u5f0f\uff1a \n1\u3001\u5229\u7528localtime()\u51fd\u6570\u5c06\u65f6\u95f4\u6233\u8f6c\u5316\u6210localtime\u7684\u683c\u5f0f\n2\u3001\u5229\u7528strftime()\u51fd\u6570\u91cd\u65b0\u683c\u5f0f\u5316\u65f6\u95f4<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"209\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-3.png\" alt=\"\" class=\"wp-image-4018\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-3.png 616w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-3-300x102.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-3-600x204.png 600w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u7684\u65f6\u95f4\u6233\u4e3a\u624b\u52a8\u5199\u4e0a\u53bb\u7684\uff0c\u5982\u679c\u8981\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u6233\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>timestamp = int(time.time())<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001<strong>\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u7c7b\u578b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u9996\u5148\u5bfc\u5165\u5185\u7f6e\u6a21\u5757platfrom\uff0c\u7136\u540e\u83b7\u53d6\u7cfb\u7edf\u7c7b\u578b\nsystype = platform.system()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"113\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-6.png\" alt=\"\" class=\"wp-image-4062\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-6.png 551w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/1-6-300x62.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"94\" src=\"http:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/2-3.png\" alt=\"\" class=\"wp-image-4063\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/2-3.png 553w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/06\/2-3-300x51.png 300w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5\u3001Python\u6267\u884cshell\u547d\u4ee4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>##############python2###################\nimport commands               \/\/python2\u7528commands\u6a21\u5757\ncommand = commands.getoutput(\"shell\u547d\u4ee4\")\n##############python3###################\nimport subprocess            \/\/python3\u7528subprocess\u6a21\u5757\ncommand = subprocess.getoutput(\"shell\u547d\u4ee4\")<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6\u3001\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5b57\u5178<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import ast                  #\u901a\u8fc7ast\u6a21\u5757\u5b9e\u73b0\ndict = ast.literal_eval(var) #\u5c06\u5b57\u7b26\u4e32var\u8f6c\u6362\u4e3a\u5b57\u5178<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">conda\u5e38\u7528\u547d\u4ee4<\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>conda install pandas numpy   \/\/\u5b89\u88c5\u5305\nconda list pandas            \/\/\u67e5\u770b\u5305\nconda update packagename    \/\/\u5347\u7ea7\u5305<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>pip installl wxpython -i https:\/\/pypi.doubanio.com\/simp [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-211","page","type-page","status-publish","hentry"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=211"}],"version-history":[{"count":28,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages\/211\/revisions"}],"predecessor-version":[{"id":18674,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/pages\/211\/revisions\/18674"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}