{"id":494,"date":"2015-01-13T12:18:30","date_gmt":"2015-01-13T04:18:30","guid":{"rendered":"http:\/\/www.withonly.com\/?p=494"},"modified":"2018-08-13T10:23:22","modified_gmt":"2018-08-13T02:23:22","slug":"python%e5%88%9d%e8%af%95","status":"publish","type":"post","link":"https:\/\/blog.5danyuan.com\/?p=494","title":{"rendered":"Python\u521d\u8bd5"},"content":{"rendered":"<p>\u5de5\u4f5c\u4e0a\u6700\u8fd1\u6709\u9047\u5230\u4e00\u4e2a\u4e8b\u60c5\uff0c\u670d\u52a1\u5668\u6536\u96c6\u7684\u65e5\u5fd7\u4fe1\u606f\u91cc\uff0c\u5bf9\u4e8e\u65e5\u671f\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u63cf\u8ff0\u91c7\u7528\u7684\u662fyyyy-M-d\u7684\u65b9\u5f0f\uff0c\u800c\u540e\u7aef\u903b\u8f91\u7a0b\u5e8f\u5bf9\u8fd9\u5757\u7684\u5904\u7406\u7684\u4e0d\u591f\uff08\u8fd9\u4e2a\u8ba9\u8863\u670d\u81ea\u5df1\u6d17\u5f88\u662f\u8ff7\u60d1\uff09\uff0c\u4f46\u7531\u4e8e\u8de8\u90e8\u95e8\u5229\u76ca\u5173\u7cfb\uff0c\u95ee\u9898\u7684\u89e3\u51b3\u4f18\u5148\u7ea7\u4e0d\u591f\u9ad8\u3002<\/p>\n<p>\u4e8e\u662f\uff0c\u4e00\u4e2a\u6298\u8877\u7684\u601d\u8def\u5c31\u662f\u5728\u540e\u7aef\u903b\u8f91\u5904\u7406\u65e5\u5fd7\u524d\uff0c\u5148\u901a\u8fc7\u67d0\u79cd\u65b9\u5f0f\u6765\u4e2a\u9884\u5904\u7406\u3002\u9012\u5f52\u904d\u5386\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u5b50\u76ee\u5f55\u548c\u6587\u4ef6\uff0c\u6253\u5f00\u6587\u4ef6\uff0c\u6b63\u5219\u67e5\u627e\u5230\u8981\u5904\u7406\u7684\u65e5\u671f\u5b57\u7b26\u4e32\uff0c\u66ff\u6362\uff0c\u7136\u540e\u4fdd\u5b58\u3002\u770b\u8d77\u6765\u4e0d\u592a\u590d\u6742\u3002<\/p>\n<p>\u7531\u4e8e\u662fLinux\u670d\u52a1\u5668\uff0c\u540c\u65f6\u4e5f\u56e0\u4e3a\u4e00\u4e9b\u539f\u56e0\uff0c\u670d\u52a1\u5668\u4e0a\u4e5f\u65e0\u6cd5\u5b89\u88c5mono\uff0c\u6240\u4ee5\u901a\u8fc7c# \u5199\u5904\u7406\u7a0b\u5e8f\u7684\u65b9\u5f0f\u5c31\u884c\u4e0d\u901a\u3002\u5269\u4e0b\u7684\u5c31\u5206\u4e3a\u4e0b\u9762\u51e0\u79cd\u601d\u8def\uff1a<\/p>\n<ol>\n<li>shell \u547d\u4ee4<\/li>\n<li>perl\/python \u811a\u672c<\/li>\n<li>C\/C++ \u7a0b\u5e8f<\/li>\n<\/ol>\n<p>\u95ee\u9898\u5c31\u5728\u4e8e\u6211\u5bf9\u8fd9\u4e9b\u90fd\u4e0d\u4f1a\uff0c\u6700\u5f00\u59cb\u662f\u60f3\u7528c++\u6765\u5904\u7406\u3002\u7136\u540e\u7f51\u4e0a\u641c\u7d22\u4e86\u4e00\u901a\u8d44\u6599\uff0c\u5bf9\u4e8e\u8de8\u5e73\u53f0\u7684c++\uff0c\u4e5f\u78b0\u5230\u4e9b\u95ee\u9898\uff0c\u4f8b\u5982io.h\u5934\u6587\u4ef6\u662f\u6ca1\u6709\u7684\uff0c\u5bf9\u4e8e\u6b63\u5219\u4f30\u8ba1\u8fd8\u5f97\u7528boost\u4e4b\u7c7b\u7684\uff0c\u7136\u540e\u540e\u9762\u4f7f\u7528 strncat \u8fd9\u6837\u7684\u51fd\u6570\u7b80\u76f4\u662f\u7ed9\u5f04\u6076\u5fc3\u4e86\u3002\u6240\u4ee5\u5728\u8fde\u6284\u5e26\u731c\u5730\u5199\u5b8c\u76ee\u5f55\u904d\u5386\u540e\uff0c\u6211\u5c31\u653e\u5f03\u4e86\u3002Java \u7a0b\u5e8f\uff0c\u6211\u89c9\u5f97\u8fd8\u662f\u7b97\u4e86\u5427\u3002<\/p>\n<p>\u6211\u89c9\u5f97\u4e3a\u89e3\u51b3\u8fd9\u4e2a\u4e8b\u60c5\u53bb\u5b66\u4e00\u4e2a\u8bed\u8a00\uff0c\u6210\u672c\u662f\u4e0d\u662f\u592a\u9ad8\u4e86\u70b9\uff0c\u60f3\u62b1\u4e2a\u5927\u817f\u3002\u627e\u5230\u4e86@\u5c48\u5c48\uff0c\u4ed6\u5f88\u5feb\u5c31\u7ed9\u51fa\u4e86\u7b54\u6848\uff0c\u8fd9\u5c31\u662f\u5dee\u8ddd\u3002<\/p>\n<p>for i in `ls *.txt`;do mv -f $i `echo $i | sed &#8216;s\/-\\([0-9]\\)\/0\\1\/g&#8217;`;done<\/p>\n<p>\u867d\u7136\u4e0d\u80fd\u5b8c\u5168\u770b\u61c2\u5565\u610f\u601d\uff0c\u4e0d\u8fc7\u770b\u8d77\u6765\u5f88\u7eda\u4e3d\uff0c\u5bf9\u4e0d\u5bf9\uff5e\u591a\u8c22\u5c48\u5c48\u7684\u5e2e\u52a9\u3002<\/p>\n<p>\u540e\u6765\u7f51\u4e0a\u53c8\u4e0b\u4e86\u4e2aPython\u7535\u5b50\u7248\u6559\u7a0b\uff0c\u7b80\u5355\u770b\u4e86\u4e0b\uff0c\u7f51\u4e0a\u5404\u79cd\u641c\u7d22\u548c\u6284\u88ad\uff0c\u6700\u540e\u5f04\u4e86\u4e2aPython\u7684\u811a\u672c\uff0c\u4e5f\u7b97\u662f\u52c9\u5f3a\u4ea4\u5dee\u5427\u3002<\/p>\n<p><a href=\"\/wp-content\/uploads\/2015\/01\/code.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-496\" src=\"\/wp-content\/uploads\/2015\/01\/code.jpg\" alt=\"code\" width=\"407\" height=\"881\" srcset=\"https:\/\/blog.5danyuan.com\/wp-content\/uploads\/2015\/01\/code.jpg 407w, https:\/\/blog.5danyuan.com\/wp-content\/uploads\/2015\/01\/code-139x300.jpg 139w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><\/a><\/p>\n<p>import os<br \/>\nimport re<br \/>\nimport sys<\/p>\n<p>dir = &#8220;\/Users\/mmcer\/temp&#8221;<br \/>\nif len(sys.argv) &gt; 2:<br \/>\ndir = sys.arg[1]<\/p>\n<p>def check(dir):<br \/>\nfor f in os.listdir(dir):<br \/>\nfile = os.path.join(dir,f);<br \/>\nif os.path.isdir(file):<br \/>\ncheck(file)<br \/>\n#pass<br \/>\nelif os.path.isfile(file):<br \/>\nif(f.startswith(&#8220;.&#8221;)):<br \/>\n#filter Linux system file<br \/>\npass<br \/>\nelse:<br \/>\nprint &#8220;path is &#8221; + file<br \/>\nthink(file)<\/p>\n<p>def think(path):<br \/>\nfile = open(path,&#8221;r&#8221;)<br \/>\ncontent = file.read()<br \/>\nfile.close();<\/p>\n<p>reg = re.compile(&#8220;(\\d{4})-(\\d+)-(\\d+)&#8221;,re.M)<br \/>\nmatches = reg.findall(content)<\/p>\n<p>for match in matches:<br \/>\nyear = match[0]<br \/>\nmonth = match[1]<br \/>\nday = match[2]<br \/>\nold = year + &#8220;-&#8221; + month + &#8220;-&#8221; + day<\/p>\n<p>_year = match[0]<br \/>\n_month = match[1]<br \/>\n_day = match[2]<\/p>\n<p>if len(year) == 2:<br \/>\n_year = &#8220;20&#8221; + year<br \/>\nif(len(month) == 1):<br \/>\n_month = &#8220;0&#8221; + month<br \/>\nif(len(day) == 1):<br \/>\n_day = &#8220;0&#8221; + day<\/p>\n<p>newStr = _year +&#8221;-&#8221; + _month + &#8220;-&#8221; + _day<\/p>\n<p>content = content.replace(old,newStr)<\/p>\n<p>file = open(path,&#8221;w&#8221;)<br \/>\nfile.write(content)<br \/>\nfile.close()<\/p>\n<p>check(dir)<\/p>\n<p>\u4e24\u79cd\u601d\u8def\u90fd\u63d0\u4f9b\u7ed9\u5bf9\u65b9\u4e86\uff0c\u81f3\u4e8e\u5982\u4f55\u9009\u62e9\u5c31\u770b\u4eba\u5bb6\u600e\u4e48\u4f7f\u7528\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5de5\u4f5c\u4e0a\u6700\u8fd1\u6709\u9047\u5230\u4e00\u4e2a\u4e8b\u60c5\uff0c\u670d\u52a1\u5668\u6536\u96c6\u7684\u65e5\u5fd7\u4fe1\u606f\u91cc\uff0c\u5bf9\u4e8e\u65e5\u671f\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u63cf\u8ff0\u91c7\u7528\u7684\u662fyyyy-M-d\u7684\u65b9\u5f0f\uff0c\u800c\u540e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[217],"class_list":["post-494","post","type-post","status-publish","format-standard","hentry","category-daily","tag-python"],"_links":{"self":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=494"}],"version-history":[{"count":0,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/494\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}