<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7039237828665137460</id><updated>2025-12-29T11:57:41.723-08:00</updated><category term="Python"/><category term="Office"/><category term="Windows"/><category term="命令提示字元"/><category term="硬體相關資訊"/><category term="部落格小玩意製作"/><category term="其他"/><category term="Software"/><category term="資訊教學"/><category term="軟體分享及介紹"/><category term="電腦相關知識"/><category term="AutoIT"/><category term="Ubuntu"/><category term="Windows Server"/><category term="文字符號"/><category term="病毒"/><category term="Lotus notes"/><category term="好物"/><title type='text'>Jimmy筆記</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>大寶貝☆小寶貝★幸福的窩</name><uri>http://www.blogger.com/profile/08807391112592185071</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>200</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-5724432293342132121</id><published>2022-02-15T00:42:00.001-08:00</published><updated>2022-02-15T00:42:24.667-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><title type='text'>Ubuntu-Journalctl查看系統日誌</title><content type='html'>&lt;p&gt;&amp;nbsp;近期所使用Ubuntu系統24小時開著，進行跑Python程式使用，但跑個2~3天，排程就無法正常寄信，SSH連線也無法正常連線，經查看後為wifi連線問題，暫先使用腳本排程進行重開wifi。&lt;/p&gt;&lt;p&gt;以下為記錄Journalctl指令。&lt;/p&gt;&lt;p&gt;使用Journalctl來從系統日誌上查看看問題。&lt;/p&gt;&lt;p&gt;journalctl #查看所有日誌。&lt;/p&gt;&lt;p&gt;journalctl -b -1 #從上啟動電腦後的日誌記錄開始查看。&lt;/p&gt;&lt;p&gt;journalctl -S &quot;2022-01-01&quot; -U &quot;2022-01-03 11:00&quot; #查看日期區間日誌。&lt;/p&gt;&lt;p&gt;journalctl _PID=66 #針對欄位查詢，程序代碼為66的。&lt;/p&gt;&lt;p&gt;journalctl _UID=1&amp;nbsp; #針對使用者查詢。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/5724432293342132121/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2022/02/ubuntu-journalctl.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5724432293342132121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5724432293342132121'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2022/02/ubuntu-journalctl.html' title='Ubuntu-Journalctl查看系統日誌'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-5677371673858202815</id><published>2022-02-07T07:48:00.000-08:00</published><updated>2022-02-09T21:36:39.889-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="電腦相關知識"/><title type='text'>鍵盤-羅技K270無線鍵盤_USB3.X干擾</title><content type='html'>&lt;p&gt;&amp;nbsp; &amp;nbsp; 近期將鍵盤改用羅技K270無線鍵盤，一開始使用時很正常反應也很沒延遲情況，近期因筆電需外出，將無線鍵盤接收器先行拔掉。&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;外出回來後將無線鍵盤接受器插入，打字時發生許多異常情況，打字會不斷重覆單一按鍵，或單點一次Backspace鍵變成連續退除，造成不少困擾。&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; ASUS 網站：https://www.asus.com/tw/support/FAQ/1004004/&lt;/p&gt;&lt;p&gt;&amp;nbsp; 有表示此問題，為USB3.0孔和無線鍵盤的傳輸頻率2.4Ghz接近，會產生干擾。&lt;/p&gt;&lt;p&gt;解決方式：&lt;/p&gt;&lt;p&gt;一、改插USB 2.0孔。&lt;/p&gt;&lt;p&gt;二、使用USB2.0延長線。&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/5677371673858202815/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2022/02/k270usb3x.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5677371673858202815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5677371673858202815'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2022/02/k270usb3x.html' title='鍵盤-羅技K270無線鍵盤_USB3.X干擾'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-5351371256927404258</id><published>2022-01-13T04:22:00.000-08:00</published><updated>2022-02-09T21:36:40.246-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><title type='text'>Ubuntu-apt-get安裝、查詢、移除指令</title><content type='html'>&lt;p&gt;&amp;nbsp;記錄Ubuntu、在命令中使用新增、查詢、移除套件指令。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用權限指令更新套件清單&lt;/p&gt;&lt;p&gt;sudo apt-get update&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用權限指令更新已安裝套件。&lt;/p&gt;&lt;p&gt;sudo apt-get upgrade&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用權限指令安裝套件&lt;/p&gt;&lt;p&gt;sudo apt-get install &amp;lt;Package&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用權限指令重新安裝套件&lt;/p&gt;&lt;p&gt;sudo apt-get --reinstall install &amp;lt;Package&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用權限指令安裝多個套件&lt;/p&gt;&lt;p&gt;sudo apt-get install &amp;lt;Package1&amp;gt; &amp;lt;Package2&amp;gt;.....&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用權限指令用除個套件--purge參數為刪除配置檔。&lt;/p&gt;&lt;p&gt;sudo apt-get remove --purge &amp;lt;Package&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;查看已安裝的套件&lt;/p&gt;&lt;p&gt;apt list --installed&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;查看線上套件可用版本&lt;/p&gt;&lt;p&gt;apt-cache madison &amp;lt;Package&amp;gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/5351371256927404258/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2022/01/ubuntu-apt-get.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5351371256927404258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5351371256927404258'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2022/01/ubuntu-apt-get.html' title='Ubuntu-apt-get安裝、查詢、移除指令'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-2869880004238425870</id><published>2022-01-13T03:36:00.000-08:00</published><updated>2022-02-09T21:36:40.458-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-pip指令應用</title><content type='html'>&lt;p&gt;記錄pip相關指令。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;參考網站：&lt;/p&gt;&lt;p&gt;Python 官網說明：&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.python.org/zh-tw/3/installing/index.html&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://docs.python.org/zh-tw/3/installing/index.html&amp;nbsp;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Pip網站：&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://pip.pypa.io/en/stable/&quot;&gt;https://pip.pypa.io/en/stable/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://pypi.org/project/pip/&quot;&gt;https://pypi.org/project/pip/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;查看Python版本&lt;/p&gt;&lt;p&gt;python --version&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;查看pip版本&lt;/p&gt;&lt;p&gt;pip --version&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;更新pip版本&lt;/p&gt;&lt;p&gt;pip install --upgrade pip&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;查看安裝套件及版本&lt;/p&gt;&lt;p&gt;pip list&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;安裝套件&lt;/p&gt;&lt;p&gt;pip install &amp;lt;Package&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;更新套件&lt;/p&gt;&lt;p&gt;pip install --upgrade &amp;lt;Package&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;移除套件&lt;/p&gt;&lt;p&gt;pip uninstall &amp;lt;Package&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/2869880004238425870/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2022/01/python-pip.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/2869880004238425870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/2869880004238425870'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2022/01/python-pip.html' title='Python-pip指令應用'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-195986290258953973</id><published>2021-12-30T18:19:00.000-08:00</published><updated>2022-02-09T21:36:40.670-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-apscheduler工作排程器</title><content type='html'>&lt;p&gt;&amp;nbsp;參考Google搜尋到的資訊，了解apscheduler套件用法。&lt;/p&gt;&lt;p&gt;常用的排工作二種方式：&lt;/p&gt;&lt;p&gt;一、apscheduler.schedulers.blocking-只執行排程的工作。&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;p&gt;二、apscheduler.schedulers.background-啟動排程工作後，繼續執行程式。&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;apscheduler.schedulers.blocking&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; BlockingScheduler&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;datetime&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定三個副程式。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;job_1&lt;/span&gt;(text):&lt;br /&gt;    &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;job_1:&#39;&lt;/span&gt;,text)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;job_2&lt;/span&gt;(text):&lt;br /&gt;    &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;job_2:&#39;&lt;/span&gt;,text)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;job_3&lt;/span&gt;(text):&lt;br /&gt;    &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;job_3:&#39;&lt;/span&gt;, text)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定時區為UTC。&lt;/span&gt;&lt;br /&gt;schedule &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; BlockingScheduler(timezone&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Asia/Taipei&#39;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#2022年1月1日執行&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#使用&#39;data&#39;一次性時間。&lt;/span&gt;&lt;br /&gt;schedule&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add_job(job_1, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;date&#39;&lt;/span&gt;, run_date&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;datetime&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;datetime(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2022&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;), args&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Happy New Year&#39;&lt;/span&gt;])&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#使用&#39;interval&#39;間段執行，weeks、days、hours、minutes、seconds。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#開始時間start_date、結束時間end_date。&lt;/span&gt;&lt;br /&gt;schedule&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add_job(job_2, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;interval&#39;&lt;/span&gt;, seconds&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, start_date&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;2022-01-01 00:00:00&#39;&lt;/span&gt;, end_date&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;2022-01-01 00:00:00&#39;&lt;/span&gt;,args&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Happy New Year&#39;&lt;/span&gt;])&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#使用cron周期執行，year、month、day、hour、minute、second。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#’*&#39;為每年、每月、每週、每日、每小時、每分鍾」每秒。例如：（second=&#39;*&#39;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#‘*/a’為除進就執行。例如：（second=&#39;*/2&#39;)每二秒執行一次。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#’a-b&#39;執行時間區間。例如：（second=&#39;10-20&#39;)在10秒到20秒間，每秒執行一次。（second=10-20/2)為區間內每二秒執行一次。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#可指定特定年、月、日、時、分、秒和區間，例如：month=&#39;7-8&#39;,hour=&#39;8-12&#39;,minute=30 7-8月每天8-12的30分鍾執行。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#每年第一天執行。&lt;/span&gt;&lt;br /&gt;schedule&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add_job(job_3, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;cron&#39;&lt;/span&gt;, year&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;*&#39;&lt;/span&gt;,day&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,args&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Happy New Year&#39;&lt;/span&gt;])&lt;br /&gt;&lt;br /&gt;schedule&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;start()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;span style=&quot;color: red; font-size: x-large;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Happy New Year&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/195986290258953973/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-apscheduler.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/195986290258953973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/195986290258953973'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-apscheduler.html' title='Python-apscheduler工作排程器'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-3606325704316045079</id><published>2021-12-22T09:13:00.000-08:00</published><updated>2022-02-09T21:36:40.888-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-二維Dictionary字典格式使用</title><content type='html'>&lt;p&gt;想使用二維字典做為資料整理成所需的格式，想把各ID的三天內獎金顯示出來。&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: white;&quot;&gt;使用：&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;字典&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;update({KeyName: {}})&amp;nbsp; &amp;nbsp;進行新增字典key。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;br /&gt;30&lt;br /&gt;31&lt;br /&gt;32&lt;br /&gt;33&lt;br /&gt;34&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定ID編號。&lt;/span&gt;&lt;br /&gt;ID_Number&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;000001&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;000002&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;000003&#39;&lt;/span&gt;]&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定資料。&lt;/span&gt;&lt;br /&gt;Bonus&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;{&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20210101&lt;/span&gt;:[ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10000&lt;/span&gt;,ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;15000&lt;/span&gt;,ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;18000&lt;/span&gt;],&lt;br /&gt;      &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20210102&lt;/span&gt;:[ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20000&lt;/span&gt;,ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;25000&lt;/span&gt;,ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;28000&lt;/span&gt;],&lt;br /&gt;      &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20210103&lt;/span&gt;:[ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;30000&lt;/span&gt;,ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;35000&lt;/span&gt;,ID_Number[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;],&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;38000&lt;/span&gt;]}&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#指定日期。&lt;/span&gt;&lt;br /&gt;Date&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;20210101&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定dictionary格式。&lt;/span&gt;&lt;br /&gt;All_Data&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;{}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#將三個日期中將金的資料整理到同個ID下。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; d &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Bonus:&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#針對3個ID進行資料匯入。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; x &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt; (&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(ID_Number)):&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#判斷dictiaonary資料中沒此ID進行加入。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;not&lt;/span&gt; ID_Number[x] &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; All_Data:&lt;br /&gt;          &lt;span style=&quot;color: #888888;&quot;&gt;#加入ID為key值。&lt;/span&gt;&lt;br /&gt;          All_Data&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;update({ID_Number[x]: {}})&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;# 判斷dictiaonary資料中沒此日期進行加入。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;not&lt;/span&gt; d &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; All_Data[ID_Number[x]]:&lt;br /&gt;          &lt;span style=&quot;color: #888888;&quot;&gt;#加入日期為Key值。&lt;/span&gt;&lt;br /&gt;          All_Data[ID_Number[x]]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;update({d:&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;None&lt;/span&gt;})&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#進行ID_Number判斷寫入資料。&lt;/span&gt;&lt;br /&gt;          &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; ID_Number[x] &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;000001&#39;&lt;/span&gt;:&lt;br /&gt;            All_Data[ID_Number[x]][d] &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Bonus[d][&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;br /&gt;          &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; ID_Number[x] &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;000002&#39;&lt;/span&gt;:&lt;br /&gt;            All_Data[ID_Number[x]][d] &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Bonus[d][&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;]&lt;br /&gt;          &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; ID_Number[x] &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;000003&#39;&lt;/span&gt;:&lt;br /&gt;            All_Data[ID_Number[x]][d] &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Bonus[d][&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(All_Data)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; a &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; All_Data:&lt;br /&gt;    &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(a,All_Data[a])&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjnUxkvJMB-j_8DjdMaDdWhyH46IxNzCOa9gtt8qdTiBU280B8wL0CB0ixHFmOQgTyFlu2UHdmt33K2roVFCClYQxxJEI154ION9mrsM2OyoeJeMJCEjrpEJiEmipeT7Kao-5m01g94eRFNwxN7rkvclI7yEabDro8ZQp1nGsQofBkgQ9ghP0hioCOk=s1284&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;145&quot; data-original-width=&quot;1284&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjnUxkvJMB-j_8DjdMaDdWhyH46IxNzCOa9gtt8qdTiBU280B8wL0CB0ixHFmOQgTyFlu2UHdmt33K2roVFCClYQxxJEI154ION9mrsM2OyoeJeMJCEjrpEJiEmipeT7Kao-5m01g94eRFNwxN7rkvclI7yEabDro8ZQp1nGsQofBkgQ9ghP0hioCOk=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/3606325704316045079/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-dictionary.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3606325704316045079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3606325704316045079'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-dictionary.html' title='Python-二維Dictionary字典格式使用'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjnUxkvJMB-j_8DjdMaDdWhyH46IxNzCOa9gtt8qdTiBU280B8wL0CB0ixHFmOQgTyFlu2UHdmt33K2roVFCClYQxxJEI154ION9mrsM2OyoeJeMJCEjrpEJiEmipeT7Kao-5m01g94eRFNwxN7rkvclI7yEabDro8ZQp1nGsQofBkgQ9ghP0hioCOk=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-8160464559860104179</id><published>2021-12-13T07:56:00.000-08:00</published><updated>2022-02-09T21:36:41.105-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-使用日期當字典的key值</title><content type='html'>&lt;p&gt;&amp;nbsp;針對每日的文件進行整理，在讀取資料時以字典的格式，將Key值為日期。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;datetime&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;random&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定data資料類別為字典格式。&lt;/span&gt;&lt;br /&gt;data &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; {}&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#抓取現在日期。&lt;/span&gt;&lt;br /&gt;date &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; datetime&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;datetime&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;now()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定回傳資料。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Data&lt;/span&gt;(date):&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#回傳亂數值。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; random&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;randrange(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;100&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#抓取7天的資料。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(data) &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt;:&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#抓取資料KEY值為日期。&lt;/span&gt;&lt;br /&gt;    data[date&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;date()] &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Data(date)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#減一天。&lt;/span&gt;&lt;br /&gt;    date &lt;span style=&quot;color: #333333;&quot;&gt;-=&lt;/span&gt; datetime&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;timedelta(days&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(data)&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(data[datetime&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;date(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2021&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;12&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;13&lt;/span&gt;)])&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;字典內容key值為日期：&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiK5IsKTsGEOAQ9qRyDtMy6cIWo207bZp2YHg48w0FbT7DUilohHXxg8x6KVqWa0nPvOwcGHDIgcB7Snv5z-N2304LFyBvAhjLgW3Gwobor9PYIBSFcZ0imNAJN0GOiKVQe3_qnw4npQcGEJxMAfT70wwUWA8xEp9tsFCfvLhQ1bFk1EOphzjVCYp6J=s677&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;33&quot; data-original-width=&quot;677&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiK5IsKTsGEOAQ9qRyDtMy6cIWo207bZp2YHg48w0FbT7DUilohHXxg8x6KVqWa0nPvOwcGHDIgcB7Snv5z-N2304LFyBvAhjLgW3Gwobor9PYIBSFcZ0imNAJN0GOiKVQe3_qnw4npQcGEJxMAfT70wwUWA8xEp9tsFCfvLhQ1bFk1EOphzjVCYp6J=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/8160464559860104179/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-key.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/8160464559860104179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/8160464559860104179'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-key.html' title='Python-使用日期當字典的key值'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEiK5IsKTsGEOAQ9qRyDtMy6cIWo207bZp2YHg48w0FbT7DUilohHXxg8x6KVqWa0nPvOwcGHDIgcB7Snv5z-N2304LFyBvAhjLgW3Gwobor9PYIBSFcZ0imNAJN0GOiKVQe3_qnw4npQcGEJxMAfT70wwUWA8xEp9tsFCfvLhQ1bFk1EOphzjVCYp6J=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-5469300846655269700</id><published>2021-12-11T09:19:00.000-08:00</published><updated>2022-02-09T21:36:41.320-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-字串處理使用一行程式碼,For IF中括號。</title><content type='html'>&lt;p&gt;&amp;nbsp;上網查詢字串處理相關資料，查看到一行就可以處理，一開始不是很理解，沒有冒號而且順序也和平常寫法不同，花了時間研究一下，&lt;/p&gt;&lt;p&gt;用法為中括號[結果 迴圈 條件]。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定一個字串。&lt;/span&gt;&lt;br /&gt;Text&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;/abcd%-/efgh%-/wx%-/yz%&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定一個字典，ord用於轉換ASCII碼，且使用迴圈產生多個字元的字典。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# ASCII碼參考網址：https://zh.wikipedia.org/zh-tw/ASCII。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;({&lt;span style=&quot;color: #007020;&quot;&gt;ord&lt;/span&gt;(t): &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;None&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; t &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;/%&#39;&lt;/span&gt;})&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#一行處理字串，將字串以有’-‘符號進行分割，需分割後字元大於5。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#最後進行特定字元轉換’/&#39;和&#39;%&#39;轉成空後印出。&lt;/span&gt;&lt;br /&gt;[&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(d&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;translate({&lt;span style=&quot;color: #007020;&quot;&gt;ord&lt;/span&gt;(t): &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;None&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; t &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;/%&#39;&lt;/span&gt;})) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; d &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Text&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;split(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;-&#39;&lt;/span&gt;) &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(d)&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;]&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjVH9xWizGUyUyRL1haJg7g6KQYGk8AtcSsSNoI6XBevoDvzmO6kLcamDPbWQIDgtQRde5QlGE1xYZEY-SwgO1U9FYGa0YZo4nSHePUcirc7ae7AVF81hGz98RSKvgEVtPJMHNmOJ9YuIB7V8Xb20JqU4dRtKDRVjlzEQyIiWw9snZxUbe6wnI0uKES=s261&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;85&quot; data-original-width=&quot;261&quot; height=&quot;85&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjVH9xWizGUyUyRL1haJg7g6KQYGk8AtcSsSNoI6XBevoDvzmO6kLcamDPbWQIDgtQRde5QlGE1xYZEY-SwgO1U9FYGa0YZo4nSHePUcirc7ae7AVF81hGz98RSKvgEVtPJMHNmOJ9YuIB7V8Xb20JqU4dRtKDRVjlzEQyIiWw9snZxUbe6wnI0uKES&quot; width=&quot;261&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/5469300846655269700/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-for-if.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5469300846655269700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/5469300846655269700'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-for-if.html' title='Python-字串處理使用一行程式碼,For IF中括號。'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjVH9xWizGUyUyRL1haJg7g6KQYGk8AtcSsSNoI6XBevoDvzmO6kLcamDPbWQIDgtQRde5QlGE1xYZEY-SwgO1U9FYGa0YZo4nSHePUcirc7ae7AVF81hGz98RSKvgEVtPJMHNmOJ9YuIB7V8Xb20JqU4dRtKDRVjlzEQyIiWw9snZxUbe6wnI0uKES=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-8997452016345505601</id><published>2021-12-03T08:46:00.000-08:00</published><updated>2022-02-09T21:36:41.539-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Pandas_轉存Excel關閉index欄位</title><content type='html'>&lt;p&gt;將資料透過Pandas存成Excel檔案時，多一欄上網Google查詢，了解到Pandas存檔時預設會帶入index欄，可在&lt;span style=&quot;background-color: white;&quot;&gt;to_excel()中加入&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;index&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008800;&quot;&gt;&lt;b&gt;False。&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi3tuVnozS4ZYyEWQrgNh61jGITRDJxBUElJurVQht7hN_kfS7vnSFWZ4nI_6vfI0j3z-leVZuIuJN8J7AJVDYQavWTjifRL0h8yChrZUN8jpiuO2hKIk0X6Wz6jYdt9Y9H1otLkSppvIZxZdoCVCwPBhjQB5icQoW8a5kcKDkIVMsMXzQv62_q9Tbk=s229&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;86&quot; data-original-width=&quot;229&quot; height=&quot;86&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEi3tuVnozS4ZYyEWQrgNh61jGITRDJxBUElJurVQht7hN_kfS7vnSFWZ4nI_6vfI0j3z-leVZuIuJN8J7AJVDYQavWTjifRL0h8yChrZUN8jpiuO2hKIk0X6Wz6jYdt9Y9H1otLkSppvIZxZdoCVCwPBhjQB5icQoW8a5kcKDkIVMsMXzQv62_q9Tbk&quot; width=&quot;229&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;pandas&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;pd&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Excel_file&lt;/span&gt;(path):&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#設定Pandas 二個欄位名稱。&lt;/span&gt;&lt;br /&gt;    data &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; pd&lt;br /&gt;&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;DataFrame(columns&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;ID&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;NAME&#39;&lt;/span&gt;])&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#存成Excel檔案，且不含index。&lt;/span&gt;&lt;br /&gt;    data&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;to_excel(path,index&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;False&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#路徑。&lt;/span&gt;&lt;br /&gt;    file_path&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Test.xlsx&#39;&lt;/span&gt;&lt;br /&gt;    Excel_file(file_path)&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjT_LW2cWAMNOw9-cKdjA9frS8DJIdWopAKpq6c06gSi84IYI2rUFD5i3usrV1fRck36bdxJcUZeNAV7eCU8AAz9O23-9aMRUCRnUjp3hK8ESCoAxr9A0kglucpW86gaatITtyFbIVTfo2803SRfOc1tJhJzWKk7YzAdGG6HMv3iQb6JfvIuhfsfm64=s153&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;100&quot; data-original-width=&quot;153&quot; height=&quot;100&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjT_LW2cWAMNOw9-cKdjA9frS8DJIdWopAKpq6c06gSi84IYI2rUFD5i3usrV1fRck36bdxJcUZeNAV7eCU8AAz9O23-9aMRUCRnUjp3hK8ESCoAxr9A0kglucpW86gaatITtyFbIVTfo2803SRfOc1tJhJzWKk7YzAdGG6HMv3iQb6JfvIuhfsfm64&quot; width=&quot;153&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/8997452016345505601/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-pandasexcelindex.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/8997452016345505601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/8997452016345505601'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-pandasexcelindex.html' title='Python-Pandas_轉存Excel關閉index欄位'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEi3tuVnozS4ZYyEWQrgNh61jGITRDJxBUElJurVQht7hN_kfS7vnSFWZ4nI_6vfI0j3z-leVZuIuJN8J7AJVDYQavWTjifRL0h8yChrZUN8jpiuO2hKIk0X6Wz6jYdt9Y9H1otLkSppvIZxZdoCVCwPBhjQB5icQoW8a5kcKDkIVMsMXzQv62_q9Tbk=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-3466183093558389051</id><published>2021-12-02T08:02:00.000-08:00</published><updated>2022-02-09T21:36:41.753-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Pandas_抓取CSV檔案內的值創件新的Excel檔案</title><content type='html'>&lt;p&gt;&amp;nbsp;想將CSV第一欄的值，做為Excel檔案名稱進行資料分類使用。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;os&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;pandas&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;pd&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;New_Excel&lt;/span&gt;(Path):&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#讀取CSV檔案內容。&lt;/span&gt;&lt;br /&gt;    df &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; pd&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;read_csv(Path)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#設定資料啟始值。&lt;/span&gt;&lt;br /&gt;    x&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#讀取每一個值，創件一新的Excel檔案,shape[0]rows,[1]columns。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;while&lt;/span&gt; x &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt; df&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;shape[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]:&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#讀取Name欄的值。  &lt;/span&gt;&lt;br /&gt;      Name &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; df[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Name&quot;&lt;/span&gt;][x]&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#讀取Name欄的值，持續往下讀取。&lt;/span&gt;&lt;br /&gt;      x&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#設定一個空白的DataFrame資料。&lt;/span&gt;&lt;br /&gt;      data &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; pd&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;DataFrame()&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#依讀取到的Name值做為檔名。&lt;/span&gt;&lt;br /&gt;      file_Name&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(Name)&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;.xlsx&#39;&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#新增一個Excel，檔名為Name欄所讀到的值。&lt;/span&gt;&lt;br /&gt;      data&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;to_excel(file_Name)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt; &lt;span style=&quot;color: #888888;&quot;&gt;#設定路徑。&lt;/span&gt;&lt;br /&gt; file_path&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Name.csv&quot;&lt;/span&gt;&lt;br /&gt; &lt;span style=&quot;color: #888888;&quot;&gt;#執行New_Excel帶入路徑。&lt;/span&gt;&lt;br /&gt; New_Excel(file_path)&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEigFmXNbzetdZw0eUdKXcQxLCngiHjsahCTCMz9uSHOirC9NJMqY4m0D3zL-j_HGZrs67fhTIUCj7IUJsgyLNylVfedrzBZ2w3wE4xV2J2WWrPqNXGjpy93vUXjYC_8OArxPcrNeoS9dsn91zj5bg10tG4o27wmS-13hGOX4RUVF93Gmo2-su-bHNHi=s454&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;454&quot; data-original-width=&quot;106&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEigFmXNbzetdZw0eUdKXcQxLCngiHjsahCTCMz9uSHOirC9NJMqY4m0D3zL-j_HGZrs67fhTIUCj7IUJsgyLNylVfedrzBZ2w3wE4xV2J2WWrPqNXGjpy93vUXjYC_8OArxPcrNeoS9dsn91zj5bg10tG4o27wmS-13hGOX4RUVF93Gmo2-su-bHNHi=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgMKe8BrrFAc2j0iX90QO8nMqIzNjKF0xfpR-ih3sKUaE5qWqIwWWjBPvliG0_HK1oVFvBtDAHBwGnwYAYpXQ3ap5F4rSa59xSADsqopDH-b10KKuHlucFB2eJGrPWWNjZodi2xLGZX7zF57821HQ8dwkdM2pueLeRY7IyzfkFLHUC9780exTGfPw6l=s612&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;612&quot; data-original-width=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgMKe8BrrFAc2j0iX90QO8nMqIzNjKF0xfpR-ih3sKUaE5qWqIwWWjBPvliG0_HK1oVFvBtDAHBwGnwYAYpXQ3ap5F4rSa59xSADsqopDH-b10KKuHlucFB2eJGrPWWNjZodi2xLGZX7zF57821HQ8dwkdM2pueLeRY7IyzfkFLHUC9780exTGfPw6l=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/3466183093558389051/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-pandascsvexcel.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3466183093558389051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3466183093558389051'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/12/python-pandascsvexcel.html' title='Python-Pandas_抓取CSV檔案內的值創件新的Excel檔案'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEigFmXNbzetdZw0eUdKXcQxLCngiHjsahCTCMz9uSHOirC9NJMqY4m0D3zL-j_HGZrs67fhTIUCj7IUJsgyLNylVfedrzBZ2w3wE4xV2J2WWrPqNXGjpy93vUXjYC_8OArxPcrNeoS9dsn91zj5bg10tG4o27wmS-13hGOX4RUVF93Gmo2-su-bHNHi=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-4262733944473434130</id><published>2021-11-24T18:13:00.000-08:00</published><updated>2022-02-09T21:36:41.967-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-遞迴</title><content type='html'>&lt;p&gt;&amp;nbsp;一對兔子，三個月後長大生一對兔子，之後每個月生一對，持續下去使用遞迴做計算。&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;Source Sans Pro&amp;quot;, Arial, sans-serif; font-size: 18px;&quot;&gt;1,1,2,3,5,8,13,21,34,55,89&lt;/span&gt;&lt;/p&gt;&lt;p&gt;程式碼以5個月做計算。&lt;/p&gt;&lt;p&gt;使用遞迴反覆進行執行，retrun做為中斷。&lt;/p&gt;&lt;p&gt;將程式連連續呼叫自已，直到條件滿足回傳值，反覆執行直到輸入的數字進行運算判斷後，都被滿足。&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;5&lt;br /&gt;6&lt;br /&gt;7&lt;br /&gt;8&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;rabbit&lt;/span&gt;(Number,G):&lt;br /&gt;     &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(Number, G)&lt;br /&gt;     &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Number &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;or&lt;/span&gt; Number &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;:&lt;br /&gt;         &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Return_1:&#39;&lt;/span&gt;,Number,G)&lt;br /&gt;         &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;     &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; rabbit(Number&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&#39;-1&#39;&quot;&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;rabbit(Number&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&#39;-2&#39;&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;   &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(rabbit(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Initial&#39;&lt;/span&gt;))&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;結果：&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhZyZzwGT6nq4GL03BggAP2pjSEZDL1BsMAN50pER1SkYiHIn_HcKaUNmdgSZhW_puLK9J0jkpH3urFnibasMxV8mFy9hgwtHPUsjHpONfPN0nD3PoHPj_4rDPjvfW8xXVyCKkESMxwbtgZ9gU77wvcsaDqJa-nQC4v60MYCEqGUeSwRshYaQO4uWRs=s410&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;410&quot; data-original-width=&quot;279&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhZyZzwGT6nq4GL03BggAP2pjSEZDL1BsMAN50pER1SkYiHIn_HcKaUNmdgSZhW_puLK9J0jkpH3urFnibasMxV8mFy9hgwtHPUsjHpONfPN0nD3PoHPj_4rDPjvfW8xXVyCKkESMxwbtgZ9gU77wvcsaDqJa-nQC4v60MYCEqGUeSwRshYaQO4uWRs=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/4262733944473434130/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/4262733944473434130'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/4262733944473434130'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python.html' title='Python-遞迴'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhZyZzwGT6nq4GL03BggAP2pjSEZDL1BsMAN50pER1SkYiHIn_HcKaUNmdgSZhW_puLK9J0jkpH3urFnibasMxV8mFy9hgwtHPUsjHpONfPN0nD3PoHPj_4rDPjvfW8xXVyCKkESMxwbtgZ9gU77wvcsaDqJa-nQC4v60MYCEqGUeSwRshYaQO4uWRs=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-6496259388872455763</id><published>2021-11-20T18:14:00.000-08:00</published><updated>2022-02-09T21:36:42.179-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Copy陣列連動問題</title><content type='html'>&lt;p&gt;&amp;nbsp;想對資料進行排序，但不想動到原資料，故使用新資料=原資料方式，創造新資料出來，進行排序，最後查看的結果原資料也跟著修改。&lt;/p&gt;&lt;p&gt;上網查查相關資料，原來Python同個陣列存在記憶體位址相同，可使用[:]重新設定index值，或list型態。&lt;/p&gt;&lt;p&gt;如：Data[3,2,1]&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; New_Data=Data[:]&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; New_Data=list(Data)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;參考：&lt;a href=&quot;https://skylinelimit.blogspot.com/2018/04/python-variable-reference.html&quot;&gt;https://skylinelimit.blogspot.com/2018/04/python-variable-reference.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Bubble_Sort&lt;/span&gt;(Sort):&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(Sort)&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;):&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(Sort)&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;i):&lt;br /&gt;            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Sort[j] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; Sort[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]:&lt;br /&gt;                temp&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Sort[j]&lt;br /&gt;                Sort[j]&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Sort[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;br /&gt;                Sort[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;temp&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; Sort&lt;br /&gt;&lt;br /&gt;Number&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;br /&gt;Number_Sort&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Number&lt;br /&gt;Number_Copy&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Number[:]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;same copy after sort:&#39;&lt;/span&gt;,Bubble_Sort(Number_Sort))&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;before sort:&#39;&lt;/span&gt;,Number)&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;\n&#39;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;index copy after sort:&#39;&lt;/span&gt;,Bubble_Sort(Number_Copy))&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;before sort:&#39;&lt;/span&gt;,Number)&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjpC1ZOOP4b7XkVsQGl9chytyiCCIVb09mCDpUaaKo4JDgDkYkT8Kphbkf4PVoMo8be2d8oASlBaQmUoctYshjyLolj-wmgjrfqqPcLbyag4ZJUygpJFVYUQtnN3kmsjLH2K_Du5I3Q01DMTW16YzJ-yfbP2aD9AUjEeGWLQK1b7FG7NKgkIwObzUWz=s481&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;177&quot; data-original-width=&quot;481&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjpC1ZOOP4b7XkVsQGl9chytyiCCIVb09mCDpUaaKo4JDgDkYkT8Kphbkf4PVoMo8be2d8oASlBaQmUoctYshjyLolj-wmgjrfqqPcLbyag4ZJUygpJFVYUQtnN3kmsjLH2K_Du5I3Q01DMTW16YzJ-yfbP2aD9AUjEeGWLQK1b7FG7NKgkIwObzUWz=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/6496259388872455763/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-copy.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/6496259388872455763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/6496259388872455763'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-copy.html' title='Python-Copy陣列連動問題'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjpC1ZOOP4b7XkVsQGl9chytyiCCIVb09mCDpUaaKo4JDgDkYkT8Kphbkf4PVoMo8be2d8oASlBaQmUoctYshjyLolj-wmgjrfqqPcLbyag4ZJUygpJFVYUQtnN3kmsjLH2K_Du5I3Q01DMTW16YzJ-yfbP2aD9AUjEeGWLQK1b7FG7NKgkIwObzUWz=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-7704018368089242876</id><published>2021-11-19T08:52:00.000-08:00</published><updated>2022-02-09T21:36:42.397-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-插入排序法</title><content type='html'>&lt;p&gt;&amp;nbsp;插入排序法，將本身和右邊值比較，右邊值較小進行交換，在持續往左邊比較，左邊值較大進行交換，直到左邊的值較小。&lt;/p&gt;&lt;p&gt;外圈先將每個值都依序比較，內圈比較後的值，若右邊小進行交換，直到左邊的值較小做停止。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定需排序的數字。&lt;/span&gt;&lt;br /&gt;Number&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;3241&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#轉成list格式。&lt;/span&gt;&lt;br /&gt;array&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;list&lt;/span&gt;(Number)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#進行插入排序法，本身比右邊大進行交換。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(array)&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;):&lt;br /&gt;  &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;第{}輪：&#39;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;format(i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;))&lt;br /&gt;  &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;初始:&#39;&lt;/span&gt;,array)&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#進行插入排序法，遇到右邊比較小的進行交換。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#一直往左邊比較，若左邊值較大進行交換，直到右邊的值比較小。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(i,&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;):&lt;br /&gt;     &lt;span style=&quot;color: #888888;&quot;&gt;#右邊的值較大，進行交換。&lt;/span&gt;&lt;br /&gt;     &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; array[j] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; array[j &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]:&lt;br /&gt;      temp&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;array[j]&lt;br /&gt;      array[j]&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;array[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;br /&gt;      array[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;temp&lt;br /&gt;     &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; array[j] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt; array[j &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]:&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;break&lt;/span&gt;&lt;br /&gt;     &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;比較結果:&#39;&lt;/span&gt;,array)&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;結果：&#39;&lt;/span&gt;,array)&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgSt_IuGL-yHxNzEs7em78iPmXyIJ29mHzWps-ljqAykndwCjtYz-Ufgr6gY0tZ8eMv5mQpA0H-8zmbZT3mCYkqBtMjoQ6IF3jsg9iawGRLGFsDof12NRUF3mROEPmNcQHJSVXm4NT9XexCjyRqu7qB2t2ADOF4l2UmM165QJsYygO75S3nT2NP_9dN=s440&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;305&quot; data-original-width=&quot;440&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgSt_IuGL-yHxNzEs7em78iPmXyIJ29mHzWps-ljqAykndwCjtYz-Ufgr6gY0tZ8eMv5mQpA0H-8zmbZT3mCYkqBtMjoQ6IF3jsg9iawGRLGFsDof12NRUF3mROEPmNcQHJSVXm4NT9XexCjyRqu7qB2t2ADOF4l2UmM165QJsYygO75S3nT2NP_9dN=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/7704018368089242876/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python_19.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/7704018368089242876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/7704018368089242876'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python_19.html' title='Python-插入排序法'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgSt_IuGL-yHxNzEs7em78iPmXyIJ29mHzWps-ljqAykndwCjtYz-Ufgr6gY0tZ8eMv5mQpA0H-8zmbZT3mCYkqBtMjoQ6IF3jsg9iawGRLGFsDof12NRUF3mROEPmNcQHJSVXm4NT9XexCjyRqu7qB2t2ADOF4l2UmM165QJsYygO75S3nT2NP_9dN=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-6029969572579918659</id><published>2021-11-18T08:25:00.000-08:00</published><updated>2022-02-09T21:36:42.608-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-氣泡排序法</title><content type='html'>&lt;p&gt;&amp;nbsp;氣泡排序法為二數相比較，較大的數往右邊移動，反覆比較後將完成順序的排列。&lt;/p&gt;&lt;p&gt;使用雙迴圈，每一次外圈跑完後，較大的值會往右邊靠齊，故內圈可減去次數。&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定需排序的數字。&lt;/span&gt;&lt;br /&gt;Number&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;3241&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#轉成list格式。&lt;/span&gt;&lt;br /&gt;array&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;list&lt;/span&gt;(Number)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#進行氣泡排序法，本身和下個一做比較。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(array)&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;):&lt;br /&gt;  &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;第{}輪：&#39;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;format(i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;))&lt;br /&gt;  &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;初始:&#39;&lt;/span&gt;,array)&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#進行氣泡排序法，遇到右邊比較小的進行交換。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#每跑一輪會將數字大的往右邊，故減1。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(array)&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;i):&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; array[j] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; array[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]:&lt;br /&gt;      temp&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;array[j]&lt;br /&gt;      array[j]&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;array[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;br /&gt;      array[j&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;temp&lt;br /&gt;    &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;過程:&#39;&lt;/span&gt;,array)&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;結果：&#39;&lt;/span&gt;,array)&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjP5tCG1zJ85c8QX_-AF8gJDSZL1SBUdVWTC7ci0Pmrnej9KJFcDEDoHX1cofnDGgF-Rh0Hplier7O3WSRV9uA823WZFVYMkXTFDreWyTPmks07hp9dR3jA3UT6053vII6MFRoDdE_nZcKVjqDNbOYcdyyFSrIu_MpoOXzp-fg3UHw1AqBcolMtf5Th=s417&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;367&quot; data-original-width=&quot;417&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjP5tCG1zJ85c8QX_-AF8gJDSZL1SBUdVWTC7ci0Pmrnej9KJFcDEDoHX1cofnDGgF-Rh0Hplier7O3WSRV9uA823WZFVYMkXTFDreWyTPmks07hp9dR3jA3UT6053vII6MFRoDdE_nZcKVjqDNbOYcdyyFSrIu_MpoOXzp-fg3UHw1AqBcolMtf5Th=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/6029969572579918659/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python_18.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/6029969572579918659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/6029969572579918659'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python_18.html' title='Python-氣泡排序法'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjP5tCG1zJ85c8QX_-AF8gJDSZL1SBUdVWTC7ci0Pmrnej9KJFcDEDoHX1cofnDGgF-Rh0Hplier7O3WSRV9uA823WZFVYMkXTFDreWyTPmks07hp9dR3jA3UT6053vII6MFRoDdE_nZcKVjqDNbOYcdyyFSrIu_MpoOXzp-fg3UHw1AqBcolMtf5Th=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-2106260922776412360</id><published>2021-11-17T07:55:00.000-08:00</published><updated>2022-02-09T21:36:42.822-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Openpyxl_Excel使用插入排序法進行排序</title><content type='html'>&lt;p&gt;&amp;nbsp;使用插入排序法，對資料進行排序。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;br /&gt;30&lt;br /&gt;31&lt;br /&gt;32&lt;br /&gt;33&lt;br /&gt;34&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 讀取EXCEL檔案。&lt;/span&gt;&lt;br /&gt;wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Datainsertionsort.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 讀取工作表。&lt;/span&gt;&lt;br /&gt;Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Data&#39;&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#調整Excel欄位宽度。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Insertion_Sort&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#設定起始欄位。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取A這一行，判斷A有幾排使用。&lt;/span&gt;&lt;br /&gt;    colummn &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Sheet[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;A&#39;&lt;/span&gt;]&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# Len為列的長度。&lt;/span&gt;&lt;br /&gt;    Len &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(colummn)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#將所有筆數跑過一次。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; x &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,Len):&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#插入排序法，將原位置和原位置加1的位置做比較，若原位置數較大和原位置加1後位置交換。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#原位置數較大和原位置加1後位置交換，在往回找是否有比原位置加1更大，有的話進行交換。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(x,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;):&lt;br /&gt;            &lt;span style=&quot;color: #888888;&quot;&gt;#判斷原位置和原位置+1的位置數值較大進行交換。&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value[:&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value[:&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;]:&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#先將原位置放到temp。&lt;/span&gt;&lt;br /&gt;                temp&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#原位置的值等於原位置+1的位置值。&lt;/span&gt;&lt;br /&gt;                Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#原位置+1的位置，等於Temp。&lt;/span&gt;&lt;br /&gt;                Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;temp&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;##判斷原位置和原位置+1的位置數值較小中止。&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value[:&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value[:&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;]:&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;break&lt;/span&gt;&lt;br /&gt;    wb&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;save(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Datainsertionsort.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    Insertion_Sort()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhFIMoOXs6uw6R52KuyYWFiTt1WJcuswaF9KsAKB41OwPvyCidDxMHw5uSSi_ffy1OJUeEjANwxHGK127nH-Y3K9HCmtlaOqbYm4E-QBUTulO4m5iqNeXFSi3hdHXmkL06zL9wspsSFQHVjQDHHQHQh1tAKwu56hRfdSkqeiCkNaQAob2KF4DCcDvS4=s1000&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;473&quot; data-original-width=&quot;1000&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhFIMoOXs6uw6R52KuyYWFiTt1WJcuswaF9KsAKB41OwPvyCidDxMHw5uSSi_ffy1OJUeEjANwxHGK127nH-Y3K9HCmtlaOqbYm4E-QBUTulO4m5iqNeXFSi3hdHXmkL06zL9wspsSFQHVjQDHHQHQh1tAKwu56hRfdSkqeiCkNaQAob2KF4DCcDvS4=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/2106260922776412360/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/2106260922776412360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/2106260922776412360'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel.html' title='Python-Openpyxl_Excel使用插入排序法進行排序'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhFIMoOXs6uw6R52KuyYWFiTt1WJcuswaF9KsAKB41OwPvyCidDxMHw5uSSi_ffy1OJUeEjANwxHGK127nH-Y3K9HCmtlaOqbYm4E-QBUTulO4m5iqNeXFSi3hdHXmkL06zL9wspsSFQHVjQDHHQHQh1tAKwu56hRfdSkqeiCkNaQAob2KF4DCcDvS4=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-6074431446093596444</id><published>2021-11-16T08:18:00.000-08:00</published><updated>2022-02-09T21:36:43.035-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Openpyxl_Excel使用氣泡排序法進行排序</title><content type='html'>&lt;p&gt;&amp;nbsp;使用氣泡排序法，針對 Excel 資料進行排序。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;br /&gt;30&lt;br /&gt;31&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 讀取EXCEL檔案。&lt;/span&gt;&lt;br /&gt;wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Databubblesort.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 讀取工作表。&lt;/span&gt;&lt;br /&gt;Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Data&#39;&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#調整Excel欄位宽度。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Bubble_Sort&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#設定起始欄位。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取A這一行，判斷A有幾排使用。&lt;/span&gt;&lt;br /&gt;    colummn &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Sheet[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;A&#39;&lt;/span&gt;]&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# Len為列的長度。&lt;/span&gt;&lt;br /&gt;    Len &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(colummn)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#將所有筆數跑過一次。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; x &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(Len):&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#氣泡排序法，將原位置和原位置加1的位置做比較，若原位置數較大和原位置加1後位置交換。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#原位置數較大和原位置加1後位置交換，最大值會先交換到最後去，故比較範圍可以-x（執行次數）。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,Len&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;x):&lt;br /&gt;            &lt;span style=&quot;color: #888888;&quot;&gt;#判斷原位置和原位置+1的位置數值較大進行交換。&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value[:&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;] &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value[:&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;]:&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#先將原位置放到temp。&lt;/span&gt;&lt;br /&gt;                temp&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#原位置的值等於原位置+1的位置值。&lt;/span&gt;&lt;br /&gt;                Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#原位置+1的位置，等於Temp。&lt;/span&gt;&lt;br /&gt;                Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;temp&lt;br /&gt;    wb&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;save(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Databubblesort.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    Bubble_Sort()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgw-m2BsAhzxgL2G7OZcSWYCRLqbyEfI5gN2YNX7OpeCNkcX7MgfazC5eXYjRSwmBu8FhWfwbDtyUIDZ0jUyJ82Apr8BoTF8cMBm-pgwEtf120LfHLjc6Ln9dMNgxe0MAsKaaQalVvRtzkVvnM09yDYenLk0c4ozCRCyAlPx19rceOh8emQRJDFB5cg=s920&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;365&quot; data-original-width=&quot;920&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgw-m2BsAhzxgL2G7OZcSWYCRLqbyEfI5gN2YNX7OpeCNkcX7MgfazC5eXYjRSwmBu8FhWfwbDtyUIDZ0jUyJ82Apr8BoTF8cMBm-pgwEtf120LfHLjc6Ln9dMNgxe0MAsKaaQalVvRtzkVvnM09yDYenLk0c4ozCRCyAlPx19rceOh8emQRJDFB5cg=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/6074431446093596444/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel_16.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/6074431446093596444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/6074431446093596444'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel_16.html' title='Python-Openpyxl_Excel使用氣泡排序法進行排序'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgw-m2BsAhzxgL2G7OZcSWYCRLqbyEfI5gN2YNX7OpeCNkcX7MgfazC5eXYjRSwmBu8FhWfwbDtyUIDZ0jUyJ82Apr8BoTF8cMBm-pgwEtf120LfHLjc6Ln9dMNgxe0MAsKaaQalVvRtzkVvnM09yDYenLk0c4ozCRCyAlPx19rceOh8emQRJDFB5cg=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-9014813082363762825</id><published>2021-11-15T06:35:00.000-08:00</published><updated>2022-02-09T21:36:43.251-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Openpyxl_調整Excel欄位寛度</title><content type='html'>&lt;p&gt;&amp;nbsp;查詢欄位中的資料最大的長度，做為調整欄位寛度的依據。&lt;/p&gt;&lt;p&gt;原使用len計算欄位資料長度，中文會被計算佔1格，故在寫一個計算中文字來增加長度。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;使用：&lt;span style=&quot;background-color: white;&quot;&gt;column_dimensions[欄位(&#39;A&#39;、&#39;B&#39;.....]&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;width&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;br /&gt;30&lt;br /&gt;31&lt;br /&gt;32&lt;br /&gt;33&lt;br /&gt;34&lt;br /&gt;35&lt;br /&gt;36&lt;br /&gt;37&lt;br /&gt;38&lt;br /&gt;39&lt;br /&gt;40&lt;br /&gt;41&lt;br /&gt;42&lt;br /&gt;43&lt;br /&gt;44&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 讀取EXCEL檔案。&lt;/span&gt;&lt;br /&gt;wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;DataColumnwidth.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 讀取工作表。&lt;/span&gt;&lt;br /&gt;Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Data&#39;&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#調整Excel欄位宽度。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Column_width&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#設定起始欄位。&lt;/span&gt;&lt;br /&gt;    x&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#判斷第一排欄位不是空值就執行設定欄位宽度。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;while&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #333333;&quot;&gt;!=&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;None&lt;/span&gt;:&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#將數字轉成文字，使用ASCII CODE。65：A、66：B&lt;/span&gt;&lt;br /&gt;         column &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;chr&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;64&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; x))&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#設定指定欄位宽度，呼叫max_width副程式判斷目前欄位中資料長度最長值。&lt;/span&gt;&lt;br /&gt;         Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;column_dimensions[column]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;width &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;max_width(x)&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#換下欄。&lt;/span&gt;&lt;br /&gt;         x &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; x &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;    wb&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;save(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;DataColumnwidth.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;max_width&lt;/span&gt;(x):&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#設定最大長度初始值。&lt;/span&gt;&lt;br /&gt;  Len_max&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#檢查整欄。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; D &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Sheet:&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#判斷是否有文字有的話長度多佔一格。&lt;/span&gt;&lt;br /&gt;    String &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#將目前欄位的值從字串轉成字元。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; j &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;D[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value):&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#判斷字元不是字母和數字，就是文中長度+1。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;not&lt;/span&gt; j&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;encode(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;utf-8&#39;&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;isalpha() &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;and&lt;/span&gt; &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;not&lt;/span&gt; j&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;isdigit():&lt;br /&gt;            String &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;String &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#判斷欄位中資料是否為空值，是的話跳過，防止空值無法使用len計算長度。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;D[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;None&lt;/span&gt;:&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;continue&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#判斷欄位的資料長度加文字多一格的長度，比記錄中的長度大就進行替換。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; Len_max &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;D[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value))&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;String:&lt;br /&gt;         Len_max &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;D[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value))&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;String&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#回傳最大長度值。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt;(Len_max)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    Column_width()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEishQd_GkjwiAnwC0bZBAh65PTwdTv0vCj8jYi1l29lNnBU9Vg9ZXki4-bm-hts9bCmT2kfGImkvuJ2OBP1DbaziP9Ft9nAa6L5XTFisPl4VUH0OrzvZxKtkmCHCiXPjGiiiJPgaWYIoR12TAm-LV0b8TAV4qPUowlLU6PIM-Q0DSPdLf_cgULCM1cG=s1013&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;504&quot; data-original-width=&quot;1013&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEishQd_GkjwiAnwC0bZBAh65PTwdTv0vCj8jYi1l29lNnBU9Vg9ZXki4-bm-hts9bCmT2kfGImkvuJ2OBP1DbaziP9Ft9nAa6L5XTFisPl4VUH0OrzvZxKtkmCHCiXPjGiiiJPgaWYIoR12TAm-LV0b8TAV4qPUowlLU6PIM-Q0DSPdLf_cgULCM1cG=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/9014813082363762825/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel_15.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/9014813082363762825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/9014813082363762825'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel_15.html' title='Python-Openpyxl_調整Excel欄位寛度'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEishQd_GkjwiAnwC0bZBAh65PTwdTv0vCj8jYi1l29lNnBU9Vg9ZXki4-bm-hts9bCmT2kfGImkvuJ2OBP1DbaziP9Ft9nAa6L5XTFisPl4VUH0OrzvZxKtkmCHCiXPjGiiiJPgaWYIoR12TAm-LV0b8TAV4qPUowlLU6PIM-Q0DSPdLf_cgULCM1cG=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-3259946529136018808</id><published>2021-11-14T07:54:00.000-08:00</published><updated>2022-02-09T21:36:43.465-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Openpyxl_更改Excel欄位背景顏色</title><content type='html'>&lt;div&gt;針對特定的資料，在背景增加顏色，已有利辨識。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Openpyxl&amp;nbsp; Color使用方法：&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://openpyxl.readthedocs.io/en/stable/_modules/openpyxl/styles/fills.html#Fill.from_tree&quot;&gt;https://openpyxl.readthedocs.io/en/stable/_modules/openpyxl/styles/fills.html#Fill.from_tree&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl.styles&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; PatternFill&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;ColorData&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取EXCEL檔案。&lt;/span&gt;&lt;br /&gt;    wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;DataColor.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取工作表。&lt;/span&gt;&lt;br /&gt;    Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Data&#39;&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Sheet:&lt;br /&gt;      &lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#判斷第三行的資料為F，背景顏色變黃。&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;F&#39;&lt;/span&gt;:&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#將背景填滿為滿色(填的方式,顏色)&lt;/span&gt;&lt;br /&gt;        yellow_bg&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; PatternFill(fill_type&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;solid&#39;&lt;/span&gt;, fgColor&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;FFC800&#39;&lt;/span&gt;)&lt;br /&gt;        Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;i[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;fill &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; yellow_bg&lt;br /&gt;&lt;br /&gt;    wb&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;save(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;DataColor.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    ColorData()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;結果：&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgJUNq7h765vPhup7tTjTGCPbIuJcgwJCn8J1sbLQOCLmnyzMXRNsn99tRObxWPhs4WNEym-Uklq4gJXmdTf1YLB4a-vUC_5WYvncxAaZuOyxmLM4HO_QRwOUf29XdTHfDtKaEBRvY8aUfva7MhGlKmjxw8yeviRBVOokswenI-KbAkMgH4uk4RuPqE=s881&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;393&quot; data-original-width=&quot;881&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgJUNq7h765vPhup7tTjTGCPbIuJcgwJCn8J1sbLQOCLmnyzMXRNsn99tRObxWPhs4WNEym-Uklq4gJXmdTf1YLB4a-vUC_5WYvncxAaZuOyxmLM4HO_QRwOUf29XdTHfDtKaEBRvY8aUfva7MhGlKmjxw8yeviRBVOokswenI-KbAkMgH4uk4RuPqE=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/3259946529136018808/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel_14.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3259946529136018808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3259946529136018808'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcel_14.html' title='Python-Openpyxl_更改Excel欄位背景顏色'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgJUNq7h765vPhup7tTjTGCPbIuJcgwJCn8J1sbLQOCLmnyzMXRNsn99tRObxWPhs4WNEym-Uklq4gJXmdTf1YLB4a-vUC_5WYvncxAaZuOyxmLM4HO_QRwOUf29XdTHfDtKaEBRvY8aUfva7MhGlKmjxw8yeviRBVOokswenI-KbAkMgH4uk4RuPqE=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-3042085279432978159</id><published>2021-11-13T07:52:00.000-08:00</published><updated>2022-02-09T21:36:43.677-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Openpyxl_判斷特定資料進行刪除列</title><content type='html'>&lt;p&gt;&amp;nbsp;Excel資料量大時，整理需要刪除特定的列，單純情況下用篩選刪除，若需判斷多行資料或反覆性需做整理動作，可使用Openpyxl 中的delete.rows(列)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;delete.rows() 此動作會讓下列往上補齊，固從第一排開始刪，若資料中有多個特定需刪除的列，會因補齊關係，會沒刪到。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;DelData&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取EXCEL檔案。&lt;/span&gt;&lt;br /&gt;    wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;DataDelRow.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取工作表。&lt;/span&gt;&lt;br /&gt;    Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Data&#39;&lt;/span&gt;]&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#讀取A這一行，判斷A有幾排使用。&lt;/span&gt;&lt;br /&gt;    colummn &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Sheet[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;A&#39;&lt;/span&gt;]&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#X為列的長度。&lt;/span&gt;&lt;br /&gt;    x&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(colummn)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#從資料的最後一列開始尋找及針對特定資料進行刪除。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;True&lt;/span&gt;:&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;# 當第列為1時中斷。&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; x &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;:&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;break&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: #888888;&quot;&gt;#第三行的資料為F，整列刪除。&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;F&#39;&lt;/span&gt;:&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#刪除列delete_rows(列）&lt;/span&gt;&lt;br /&gt;        Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;delete_rows(Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;x, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row)&lt;br /&gt;      x &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; x &lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;    wb&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;save(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;DataDelRow_OK.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    DelData()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEizh7j8stbo1n_57FN7_UiEG2Bmyk4K2T19Ou9jDN40ScOhKNCjSTItr-bM2ObHO2qPMvzPdEDYOwsuIucAUT0yqbQcVw6bsyKh2mdC_NYHPa-x3XG9m4Yn3WPZPWCn5JQXnZVpK8YeAPEdcHpfqPE6ry2ohvwvXk9EYjAwd_hJyjeCGoD2ngDvLTMp=s1031&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;353&quot; data-original-width=&quot;1031&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEizh7j8stbo1n_57FN7_UiEG2Bmyk4K2T19Ou9jDN40ScOhKNCjSTItr-bM2ObHO2qPMvzPdEDYOwsuIucAUT0yqbQcVw6bsyKh2mdC_NYHPa-x3XG9m4Yn3WPZPWCn5JQXnZVpK8YeAPEdcHpfqPE6ry2ohvwvXk9EYjAwd_hJyjeCGoD2ngDvLTMp=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhAHHzpTYI49PzmumNOoDOboeSSwl7Chc46sQFRsRgoFhYyUKWKTYkkeqfAmP1a0209ScVz1_gH_5n3qUgnuzPU8ZLomqtYOwXW748mZrfwpMLHaOZ3r4yvMNJ4T5SVE8VIPrsT8tw6Cl9xyVB4pkOBWzxd1IU0wQCIDUD0gX0uHULv0Zt0O5ddNK2O=s1056&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;353&quot; data-original-width=&quot;1056&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhAHHzpTYI49PzmumNOoDOboeSSwl7Chc46sQFRsRgoFhYyUKWKTYkkeqfAmP1a0209ScVz1_gH_5n3qUgnuzPU8ZLomqtYOwXW748mZrfwpMLHaOZ3r4yvMNJ4T5SVE8VIPrsT8tw6Cl9xyVB4pkOBWzxd1IU0wQCIDUD0gX0uHULv0Zt0O5ddNK2O=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/3042085279432978159/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxl.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3042085279432978159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/3042085279432978159'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxl.html' title='Python-Openpyxl_判斷特定資料進行刪除列'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEizh7j8stbo1n_57FN7_UiEG2Bmyk4K2T19Ou9jDN40ScOhKNCjSTItr-bM2ObHO2qPMvzPdEDYOwsuIucAUT0yqbQcVw6bsyKh2mdC_NYHPa-x3XG9m4Yn3WPZPWCn5JQXnZVpK8YeAPEdcHpfqPE6ry2ohvwvXk9EYjAwd_hJyjeCGoD2ngDvLTMp=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-749634456116446195</id><published>2021-11-12T08:12:00.000-08:00</published><updated>2022-02-09T21:36:43.889-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-使用openpyxl，完成Excel中vlookup1對多資料</title><content type='html'>&lt;p&gt;&amp;nbsp;Excel vlookup 比對搜尋到第一筆就停止，使用Python 來完成多筆資料匯出。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;openpyxl&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;VlookupData&lt;/span&gt;():&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#讀取EXCEL檔案。&lt;/span&gt;&lt;br /&gt;  wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Data.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;# 讀取工作表1。&lt;/span&gt;&lt;br /&gt;  Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Data&#39;&lt;/span&gt;]&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#讀取EXCEL檔案，用於將原資料中姓名符合條件的存到新的Excel表中。&lt;/span&gt;&lt;br /&gt;  New_wb &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; openpyxl&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;load_workbook(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;New_Data.xlsx&quot;&lt;/span&gt;)&lt;br /&gt;  New_Sheet &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; New_wb[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;sheet1&#39;&lt;/span&gt;]&lt;br /&gt;  &lt;span style=&quot;color: #888888;&quot;&gt;#從第二排開始寫入資料。&lt;/span&gt;&lt;br /&gt;  Data_row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style=&quot;color: #888888;&quot;&gt;#比對資料。&lt;/span&gt;&lt;br /&gt;  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Sheet:&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#如果是第一排就寫入表頭。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; i[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;row &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;:&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; h &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(i)):&lt;br /&gt;        New_Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;h)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; i[h&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#如果姓名為“白飛”就將相關資料，寫入新的Excel中。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; i[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;白飛&#39;&lt;/span&gt;:&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; d &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(i)):&lt;br /&gt;          New_Sheet&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;cell(row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Data_row, column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;d)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; i[d &lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;]&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;value&lt;br /&gt;      Data_row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Data_row&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;  New_wb&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;save(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;New_Data.xlsx&#39;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;  VlookupData()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEizjk3KiDCvYkWEjTZYYmFjjXuAMJBGYo-4337RRiapC1rFekBejuGqDeUnIuYN9LsQVMBemF0NU2Dq74aDq_cOlkXLQ_A2PCwV0mmBkM1rkWrLD04VZ0VuqvVeRvx7RgHGm5P20pfrcsmXMbRlUPrmGBH2ocF5jfBT-e9xU0BIVGtoY5-Zts0cG9-o=s728&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;96&quot; data-original-width=&quot;728&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEizjk3KiDCvYkWEjTZYYmFjjXuAMJBGYo-4337RRiapC1rFekBejuGqDeUnIuYN9LsQVMBemF0NU2Dq74aDq_cOlkXLQ_A2PCwV0mmBkM1rkWrLD04VZ0VuqvVeRvx7RgHGm5P20pfrcsmXMbRlUPrmGBH2ocF5jfBT-e9xU0BIVGtoY5-Zts0cG9-o=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/749634456116446195/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcelvlookup1.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/749634456116446195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/749634456116446195'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-openpyxlexcelvlookup1.html' title='Python-使用openpyxl，完成Excel中vlookup1對多資料'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEizjk3KiDCvYkWEjTZYYmFjjXuAMJBGYo-4337RRiapC1rFekBejuGqDeUnIuYN9LsQVMBemF0NU2Dq74aDq_cOlkXLQ_A2PCwV0mmBkM1rkWrLD04VZ0VuqvVeRvx7RgHGm5P20pfrcsmXMbRlUPrmGBH2ocF5jfBT-e9xU0BIVGtoY5-Zts0cG9-o=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-1770437210157807836</id><published>2021-11-11T07:49:00.000-08:00</published><updated>2022-02-09T21:36:44.102-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Software"/><title type='text'>Software-PotPlayer影音播放</title><content type='html'>&lt;p&gt;&amp;nbsp;Windows 內建支援的格式有限，有很常一段時間沒用了，剛剛開啟需要初始設定，這幾年有重灌電腦都會先安裝PotPlayer播放器，畫面簡潔好用，支援功能很多，字幕調整、明亮度調整、畫面旋轉，最重要的支援很多播放的格式，點擊二點影音檔或拉進PotPlayer即可播放。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;potplayer官網：&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://potplayer.daum.net/&quot;&gt;https://potplayer.daum.net/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;簡潔的畫面，確支援很多格式的影音檔案，影片檔案一點或拉進來立即播發。&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhH7Mk2zOoAzxXziwnHGYW3dv_a2rSQAipN9CLKqmV7Xyaft2NOcuFFB5-d3ut6kVBSkf88qgKBF5FcdxlvanISiNgnwmmwzbiWFtqW2lzMJCdZPw63Lanp2NVG2zkj_AwHO740f-nL0LEUgisR73fWmkxVgp4cCqUsVqi2fhYI4VMQ9h7EQW1N-E0T=s910&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;501&quot; data-original-width=&quot;910&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhH7Mk2zOoAzxXziwnHGYW3dv_a2rSQAipN9CLKqmV7Xyaft2NOcuFFB5-d3ut6kVBSkf88qgKBF5FcdxlvanISiNgnwmmwzbiWFtqW2lzMJCdZPw63Lanp2NVG2zkj_AwHO740f-nL0LEUgisR73fWmkxVgp4cCqUsVqi2fhYI4VMQ9h7EQW1N-E0T=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;用最多的功能，字幕選擇及調整時間。&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiW6FWVAY80wMab6R4sTzU-nrm2LmT4BPr7mWv4Fm9B1qeCc6Zfu2wv0VpF85rGDnrqZjFGQvMI6cay8p9dUWj1XxJhBfso2mzzVzmsAHnvs7ymk6kbmIKGti-0C14kMqYifUvh-nKkPw4nJU0sL2dtAMKFMU6w2yNuR4OzF7bOjrR4AWJyroj8PF3A=s977&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;493&quot; data-original-width=&quot;977&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiW6FWVAY80wMab6R4sTzU-nrm2LmT4BPr7mWv4Fm9B1qeCc6Zfu2wv0VpF85rGDnrqZjFGQvMI6cay8p9dUWj1XxJhBfso2mzzVzmsAHnvs7ymk6kbmIKGti-0C14kMqYifUvh-nKkPw4nJU0sL2dtAMKFMU6w2yNuR4OzF7bOjrR4AWJyroj8PF3A=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;若要說缺點，對我來說是更新，有時一開啟就表示要更新，需關掉程式更新完才能使用，雖然可不自動更新，但不更新又想說會不會播放不順或當掉。&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhlIcojSYr4W9AEkCEWt2ED7pxWYE0U-YcJ2P38sXhtP5ClOS4KJxDC6lxLPwmVLD2dZt-8NQfLxBf9cgXBE6Nd1u2Ifg6gXb3OP74bGCUQqsHY9jDMUi1K1bDLU1pEusBIJWk7d-SmNxptJ67Q7CzDacYuR4k3oUGpqmkyrGmPk2e5G3rldSkqccCA=s748&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;563&quot; data-original-width=&quot;748&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhlIcojSYr4W9AEkCEWt2ED7pxWYE0U-YcJ2P38sXhtP5ClOS4KJxDC6lxLPwmVLD2dZt-8NQfLxBf9cgXBE6Nd1u2Ifg6gXb3OP74bGCUQqsHY9jDMUi1K1bDLU1pEusBIJWk7d-SmNxptJ67Q7CzDacYuR4k3oUGpqmkyrGmPk2e5G3rldSkqccCA=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/1770437210157807836/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/software-potplayer.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/1770437210157807836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/1770437210157807836'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/software-potplayer.html' title='Software-PotPlayer影音播放'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhH7Mk2zOoAzxXziwnHGYW3dv_a2rSQAipN9CLKqmV7Xyaft2NOcuFFB5-d3ut6kVBSkf88qgKBF5FcdxlvanISiNgnwmmwzbiWFtqW2lzMJCdZPw63Lanp2NVG2zkj_AwHO740f-nL0LEUgisR73fWmkxVgp4cCqUsVqi2fhYI4VMQ9h7EQW1N-E0T=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-7761729264189465306</id><published>2021-11-10T07:15:00.000-08:00</published><updated>2022-02-09T21:36:44.314-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-使用Faker套件產生測試用的假資料，寫入文字檔中</title><content type='html'>&lt;p&gt;&amp;nbsp;在做程式測試時，擔心有誤刪及誤改情況，影響到重要資料。&lt;/p&gt;&lt;p&gt;希望在測試程式時先用假資料試試，如果手動創建文字部份要輸入一段時間，&lt;/p&gt;&lt;p&gt;數字部份容易出現重覆或接近的，故使用Python Faker的套件相當方便。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;官方文件網址：&lt;a href=&quot;https://faker.readthedocs.io/en/master/&quot;&gt;https://faker.readthedocs.io/en/master/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;faker&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; Faker&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;TestData&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#使用中文資料。&lt;/span&gt;&lt;br /&gt;    fake &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Faker(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;zh_TW&#39;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#創建基本資料。&lt;/span&gt;&lt;br /&gt;    Test&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;fake&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;simple_profile()&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#開啟Data.txt檔案，寫入測試用資料。&lt;/span&gt;&lt;br /&gt;    New_File &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;open&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;D:\Train\Data.txt&#39;&lt;/span&gt;, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;a&#39;&lt;/span&gt;,encoding&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;utf-8&#39;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#faker套件simple_profile所產生出來的資料形態為Dictionary。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#先將Keys寫入文件中。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; t &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Test&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;keys():&lt;br /&gt;        New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;write(t&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;,&#39;&lt;/span&gt;)&lt;br /&gt;    New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;write(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#將faker產生的資料寫入文件中，總共產生1000筆。&lt;/span&gt;&lt;br /&gt;    Go&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;while&lt;/span&gt; Go &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1000&lt;/span&gt;:&lt;br /&gt;      Test &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; fake&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;simple_profile()&lt;br /&gt;      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; d &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Test&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;values():&lt;br /&gt;          New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;write(&lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(d) &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;,&#39;&lt;/span&gt;)&lt;br /&gt;      New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;write(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;)&lt;br /&gt;      Go &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Go &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;    New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;close&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    TestData()&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgvlqqH2S6IwxMtLC9JN4WFlyXv3ceneHBRfstTM5mrzASkDkma4PLZuKeehFjVylBKMbGlqLc00K1d28PvwFl2ZHifbD_nHive9wJ9GFRd3k7tNwdqbpYJfLXsIi108MFlJ9ToUWXLO9nEcssWIYZQUI43UThftpZx-6o4slW8Di9JHtQY3nsNDYG3=s1209&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;809&quot; data-original-width=&quot;1209&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgvlqqH2S6IwxMtLC9JN4WFlyXv3ceneHBRfstTM5mrzASkDkma4PLZuKeehFjVylBKMbGlqLc00K1d28PvwFl2ZHifbD_nHive9wJ9GFRd3k7tNwdqbpYJfLXsIi108MFlJ9ToUWXLO9nEcssWIYZQUI43UThftpZx-6o4slW8Di9JHtQY3nsNDYG3=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/7761729264189465306/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-faker.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/7761729264189465306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/7761729264189465306'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-faker.html' title='Python-使用Faker套件產生測試用的假資料，寫入文字檔中'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgvlqqH2S6IwxMtLC9JN4WFlyXv3ceneHBRfstTM5mrzASkDkma4PLZuKeehFjVylBKMbGlqLc00K1d28PvwFl2ZHifbD_nHive9wJ9GFRd3k7tNwdqbpYJfLXsIi108MFlJ9ToUWXLO9nEcssWIYZQUI43UThftpZx-6o4slW8Di9JHtQY3nsNDYG3=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-9112090451047464760</id><published>2021-11-09T06:29:00.000-08:00</published><updated>2022-02-09T21:36:44.524-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-查看檔案大小及刪除0k檔案</title><content type='html'>&lt;p&gt;透過Python查詢檔案的大小及使用獲取到SIZE大小進行刪除，此程式以0K檔案為刪除目標。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;br /&gt;30&lt;br /&gt;31&lt;br /&gt;32&lt;br /&gt;33&lt;br /&gt;34&lt;br /&gt;35&lt;br /&gt;36&lt;br /&gt;37&lt;br /&gt;38&lt;br /&gt;39&lt;br /&gt;40&lt;br /&gt;41&lt;br /&gt;42&lt;br /&gt;43&lt;br /&gt;44&lt;br /&gt;45&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;os&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;time&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#找路徑下所有檔案(含子目錄下）&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Find_dir&lt;/span&gt;(path):&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#開啟文字檔案，並寫入目前時間。&lt;/span&gt;&lt;br /&gt;    New_File &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;open&lt;/span&gt;(path&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Fileremove.txt&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;a+&#39;&lt;/span&gt;)&lt;br /&gt;    New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;write(time&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;strftime(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;%Y-%m-%d %H:%M:%S&#39;&lt;/span&gt;, time&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;localtime())&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;try&lt;/span&gt;:&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;# 取得指定路徑下的所有檔案及目錄名稱名稱&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; root, directorys, files &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; os&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;walk(path):&lt;br /&gt;            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; file &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; files:&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;# 合併路徑及取得的路徑檔案及目錄名稱&lt;/span&gt;&lt;br /&gt;                full_path &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; os&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;path&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;join(root, file)&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#讀取目前檔案的Size。&lt;/span&gt;&lt;br /&gt;                File_Size &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; os&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;path&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;getsize(full_path)&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#判斷檔案大小的單位。&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; File_Size &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;:&lt;br /&gt;                   File_Size&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;round&lt;/span&gt;(File_Size&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;)&lt;br /&gt;                   Unit &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;GB&#39;&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; File_Size &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt; :&lt;br /&gt;                   File_Size &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;round&lt;/span&gt;(File_Size &lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;)&lt;br /&gt;                   Unit &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;MB&#39;&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; File_Size &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt; :&lt;br /&gt;                   File_Size &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;round&lt;/span&gt;(File_Size &lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1024&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;)&lt;br /&gt;                   Unit &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;KB&#39;&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;:&lt;br /&gt;                    Unit &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;K&#39;&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(full_path,File_Size,Unit)&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;#掃描到檔名為Fileremove.txt，不作動作。&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; file &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Fileremove.txt&#39;&lt;/span&gt;:&lt;br /&gt;                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;continue&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #888888;&quot;&gt;# 刪除0K的檔案並將檔名寫入文字檔案中。&lt;/span&gt;&lt;br /&gt;                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; File_Size &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt; :&lt;br /&gt;                    New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;write(full_path&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;)&lt;br /&gt;                    os&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;remove(full_path)&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;#關閉檔案。&lt;/span&gt;&lt;br /&gt;        New_File&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;close()&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;except&lt;/span&gt; &lt;span style=&quot;color: red; font-weight: bold;&quot;&gt;Exception&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;as&lt;/span&gt; e:&lt;br /&gt;        &lt;span style=&quot;color: #888888;&quot;&gt;# 例外顯示。&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(f&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;An Error occurred:&#39;&lt;/span&gt;, e)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; __name__ &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;__main__&#39;&lt;/span&gt;:&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#設定作業路徑。&lt;/span&gt;&lt;br /&gt;    path&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;D:&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;Train&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\\&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;br /&gt;    Find_dir(path)&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjbW_nqtL11qr6yRdK7IqycLbOfjnoQhluVidORZp4Oi4N2dsRO8IEtD3_5Nh5wFIY8vcK2FbjOXSoehFRA4ZsNE0VwGC0NJm5BtvFanOYIEW6bb9IA3AfN800GIKReBDuXBc-aGvgHTiHcQHgDVC02SUbx-ZYvpbYDD-SEHAmy6NrCP93AupmBM82p=s1067&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;405&quot; data-original-width=&quot;1067&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjbW_nqtL11qr6yRdK7IqycLbOfjnoQhluVidORZp4Oi4N2dsRO8IEtD3_5Nh5wFIY8vcK2FbjOXSoehFRA4ZsNE0VwGC0NJm5BtvFanOYIEW6bb9IA3AfN800GIKReBDuXBc-aGvgHTiHcQHgDVC02SUbx-ZYvpbYDD-SEHAmy6NrCP93AupmBM82p=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/9112090451047464760/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-0k.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/9112090451047464760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/9112090451047464760'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-0k.html' title='Python-查看檔案大小及刪除0k檔案'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjbW_nqtL11qr6yRdK7IqycLbOfjnoQhluVidORZp4Oi4N2dsRO8IEtD3_5Nh5wFIY8vcK2FbjOXSoehFRA4ZsNE0VwGC0NJm5BtvFanOYIEW6bb9IA3AfN800GIKReBDuXBc-aGvgHTiHcQHgDVC02SUbx-ZYvpbYDD-SEHAmy6NrCP93AupmBM82p=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-7522816858569166114</id><published>2021-11-08T06:21:00.000-08:00</published><updated>2022-02-09T21:36:44.735-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-Gui_Combobox元件_計算電力每月耗能</title><content type='html'>&lt;p&gt;&amp;nbsp;透過tkinter Gui視窗化使用Combobox元件，增加下拉選擇及判斷使用。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;預設選擇使用：&lt;span style=&quot;background-color: white;&quot;&gt;Combobox&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;current(&lt;span style=&quot;color: #0000dd;&quot;&gt;&lt;b&gt;0&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;(元件名.指定預設選擇項)&lt;/p&gt;&lt;p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;br /&gt;18&lt;br /&gt;19&lt;br /&gt;20&lt;br /&gt;21&lt;br /&gt;22&lt;br /&gt;23&lt;br /&gt;24&lt;br /&gt;25&lt;br /&gt;26&lt;br /&gt;27&lt;br /&gt;28&lt;br /&gt;29&lt;br /&gt;30&lt;br /&gt;31&lt;br /&gt;32&lt;br /&gt;33&lt;br /&gt;34&lt;br /&gt;35&lt;br /&gt;36&lt;br /&gt;37&lt;br /&gt;38&lt;br /&gt;39&lt;br /&gt;40&lt;br /&gt;41&lt;br /&gt;42&lt;br /&gt;43&lt;br /&gt;44&lt;br /&gt;45&lt;br /&gt;46&lt;br /&gt;47&lt;br /&gt;48&lt;br /&gt;49&lt;br /&gt;50&lt;br /&gt;51&lt;br /&gt;52&lt;br /&gt;53&lt;br /&gt;54&lt;br /&gt;55&lt;br /&gt;56&lt;br /&gt;57&lt;br /&gt;58&lt;br /&gt;59&lt;br /&gt;60&lt;br /&gt;61&lt;br /&gt;62&lt;br /&gt;63&lt;br /&gt;64&lt;br /&gt;65&lt;br /&gt;66&lt;br /&gt;67&lt;br /&gt;68&lt;br /&gt;69&lt;br /&gt;70&lt;br /&gt;71&lt;br /&gt;72&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;tkinter&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;tk&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;tkinter&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; ttk&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定視窗。&lt;/span&gt;&lt;br /&gt;window &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Tk()&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定視窗標題。&lt;/span&gt;&lt;br /&gt;window&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;title(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Electricity&#39;&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定視窗大小。&lt;/span&gt;&lt;br /&gt;window&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;geometry(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;330x270&#39;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 載入Enter事件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;Enter_key&lt;/span&gt;(event):&lt;br /&gt;    button_event()&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# Button按鈕事件。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0066bb; font-weight: bold;&quot;&gt;button_event&lt;/span&gt;():&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 取得Entry及Combobox，上的元件文字。&lt;/span&gt;&lt;br /&gt;    Input_1&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Entry_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get()&lt;br /&gt;    Input_2&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Entry_2&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get()&lt;br /&gt;    Selest_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; Combobox_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get()&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;# 清除Text_元件內容。&lt;/span&gt;&lt;br /&gt;    Text_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;delete(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;1.0&#39;&lt;/span&gt;, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;end&#39;&lt;/span&gt;)&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#判斷是Minute還是Hour，計算方式不同。&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Selest_1 &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Minute&#39;&lt;/span&gt;:&lt;br /&gt;       Use_1&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;round&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;int&lt;/span&gt;(Input_1)&lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;int&lt;/span&gt;(Input_2))&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;elif&lt;/span&gt; Selest_1 &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Hour&#39;&lt;/span&gt;:&lt;br /&gt;       Use_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;round&lt;/span&gt;(&lt;span style=&quot;color: #007020;&quot;&gt;int&lt;/span&gt;(Input_1)&lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;int&lt;/span&gt;(Input_2))&lt;br /&gt;    &lt;span style=&quot;color: #888888;&quot;&gt;#在Text元件中顯示計算結果。&lt;/span&gt;&lt;br /&gt;    Text_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;insert(tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;INSERT,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;電器電能:&#39;&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; Input_1&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;W&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;)&lt;br /&gt;    Text_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;insert(tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;INSERT,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;每日使用：&#39;&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; Input_2 &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;Selest_1&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0; color: #666666; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&lt;/span&gt;)&lt;br /&gt;    Text_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;insert(tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;INSERT,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;使用一個月約&quot;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;str&lt;/span&gt;(Use_1 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;30&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1000&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;度電&quot;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Label標籤參數（bg背景顏色、font字型格式、width宽度15個字元、高度1個字元）&lt;/span&gt;&lt;br /&gt;Label_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Label(window, bg&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;yellow&#39;&lt;/span&gt;, text&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;設備瓦數(W)&#39;&lt;/span&gt;, font&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Arial&#39;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;), width&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;, height&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, padx&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定排版方式在第一排靠左。&lt;/span&gt;&lt;br /&gt;Label_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, sticky&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;w&#39;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Label標籤參數（bg背景顏色、font字型格式、width宽度15個字元、高度1個字元）&lt;/span&gt;&lt;br /&gt;Label_2 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Label(window, bg&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;yellow&#39;&lt;/span&gt;, text&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;每日使用時間&#39;&lt;/span&gt;, font&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Arial&#39;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;), width&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;, height&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, padx&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定排版方式在第二行第一排靠左。&lt;/span&gt;&lt;br /&gt;Label_2&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, sticky&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;w&#39;&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Entry輸入方框參數（font字型格式、width宽度5個字元）&lt;/span&gt;&lt;br /&gt;Entry_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Entry(window, font&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Arial&#39;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;), width&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定排版方式在第二排。&lt;/span&gt;&lt;br /&gt;Entry_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Entry輸入方框參數（font字型格式、width宽度5個字元）&lt;/span&gt;&lt;br /&gt;Entry_2 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Entry(window, font&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Arial&#39;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;), width&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定排版方式在第二行第二排。&lt;/span&gt;&lt;br /&gt;Entry_2&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Combobox，內容為Hour跟Minute。&lt;/span&gt;&lt;br /&gt;Combobox_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; ttk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Combobox(window,values&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Hour&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Minute&#39;&lt;/span&gt;],width&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#Combobox元件預設值，Minute。&lt;/span&gt;&lt;br /&gt;Combobox_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;current(&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定排版方式在第三行第二排。&lt;/span&gt;&lt;br /&gt;Combobox_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Text元件，為顯示結果使用。&lt;/span&gt;&lt;br /&gt;Text_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Text(window, font&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Arial&#39;&lt;/span&gt;, &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;),width&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;25&lt;/span&gt;,height&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#設定排版方式在第一排且離左邊距離5，離上排10。&lt;/span&gt;&lt;br /&gt;Text_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;,columnspan&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;,padx&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;,pady&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;10&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定Button按鈕及觸發事件button_event。&lt;/span&gt;&lt;br /&gt;Button_1 &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; tk&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Button(window, text&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;送出&#39;&lt;/span&gt;, command&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;button_event)&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 設定排版方式在第三排。&lt;/span&gt;&lt;br /&gt;Button_1&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;grid(column&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;, row&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,padx&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;15&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;# 建立Enter事件。&lt;/span&gt;&lt;br /&gt;window&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;bind(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;&amp;lt;Return&amp;gt;&#39;&lt;/span&gt;, Enter_key)&lt;br /&gt;window&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;mainloop()&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;結果：&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjUMZWGlrPTbhsjwQnbR_VharuegiK4p65xx5lOdTobp4GWhEZS_Kgl4M7hwmF_f1cVF6HhEOONzYMvU20-xVhdqU3IQ2Cs9IK8Xy26HHM7Ly5CGoSc3H_gFTJ-6NnFqU6HBRatMhpjyuRIT5gJOFVafXP-AaaeJlte9RgK-AcC1OYfMZNpgSWJdXhd=s403&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;373&quot; data-original-width=&quot;403&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjUMZWGlrPTbhsjwQnbR_VharuegiK4p65xx5lOdTobp4GWhEZS_Kgl4M7hwmF_f1cVF6HhEOONzYMvU20-xVhdqU3IQ2Cs9IK8Xy26HHM7Ly5CGoSc3H_gFTJ-6NnFqU6HBRatMhpjyuRIT5gJOFVafXP-AaaeJlte9RgK-AcC1OYfMZNpgSWJdXhd=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/7522816858569166114/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-guicombobox.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/7522816858569166114'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/7522816858569166114'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-guicombobox.html' title='Python-Gui_Combobox元件_計算電力每月耗能'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjUMZWGlrPTbhsjwQnbR_VharuegiK4p65xx5lOdTobp4GWhEZS_Kgl4M7hwmF_f1cVF6HhEOONzYMvU20-xVhdqU3IQ2Cs9IK8Xy26HHM7Ly5CGoSc3H_gFTJ-6NnFqU6HBRatMhpjyuRIT5gJOFVafXP-AaaeJlte9RgK-AcC1OYfMZNpgSWJdXhd=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7039237828665137460.post-1349837593565622785</id><published>2021-11-07T04:42:00.000-08:00</published><updated>2022-02-09T21:36:44.947-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python-index使用</title><content type='html'>&lt;div&gt;記錄二個index應用方式。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; 1&lt;br /&gt; 2&lt;br /&gt; 3&lt;br /&gt; 4&lt;br /&gt; 5&lt;br /&gt; 6&lt;br /&gt; 7&lt;br /&gt; 8&lt;br /&gt; 9&lt;br /&gt;10&lt;br /&gt;11&lt;br /&gt;12&lt;br /&gt;13&lt;br /&gt;14&lt;br /&gt;15&lt;br /&gt;16&lt;br /&gt;17&lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#使用index回報位置，從Number中找出二數相加為17，並回報在Number中的二數位置。&lt;/span&gt;&lt;br /&gt;Number&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;3&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;4&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;5&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;6&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;7&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;8&lt;/span&gt;,&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;9&lt;/span&gt;]&lt;br /&gt;Two_Sum&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;17&lt;/span&gt;&lt;br /&gt;Len&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #007020;&quot;&gt;len&lt;/span&gt;(Number)&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(Number)&lt;br /&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; i &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;range&lt;/span&gt;(Len):&lt;br /&gt;    Answer&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;Two_Sum&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;Number[i]&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; Answer &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; Number[Len:]:&lt;br /&gt;       &lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;二數相加為17的位置:&#39;&lt;/span&gt;,Number&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;index(Answer),i)&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;:&lt;br /&gt;       Number&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;append(Number[i])&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#使用index回應，需要的資料中排名第幾。&lt;/span&gt;&lt;br /&gt;ZOO&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;[&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Lion&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Tiger&#39;&lt;/span&gt;,&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Elephant&#39;&lt;/span&gt;]&lt;br /&gt;&lt;span style=&quot;color: #888888;&quot;&gt;#因陣列由0開始，固加1&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #007020;&quot;&gt;print&lt;/span&gt;(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Lino在已排序的資料中，排名第幾：&#39;&lt;/span&gt;,ZOO&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;index(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Lion&#39;&lt;/span&gt;)&lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;結果：&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgcuWwCvNhGCgLr5EnUKrF9p6YRJtsgM4eqafarU03H1wrQphbiI6C_S59c1841KpwWIDIZ56GYft89zYKibFieVtfsY9wF1xljKJbL7wrVtNw5cAkvkqOCdAROTOfHRSKFjJpZgASW9y3Vz8xCNClj536-VULqj_EIXnYMMI1Lm2B0PwzZ0ZDVFacB=s425&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;95&quot; data-original-width=&quot;425&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgcuWwCvNhGCgLr5EnUKrF9p6YRJtsgM4eqafarU03H1wrQphbiI6C_S59c1841KpwWIDIZ56GYft89zYKibFieVtfsY9wF1xljKJbL7wrVtNw5cAkvkqOCdAROTOfHRSKFjJpZgASW9y3Vz8xCNClj536-VULqj_EIXnYMMI1Lm2B0PwzZ0ZDVFacB=s16000&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://bluesky0215.blogspot.com/feeds/1349837593565622785/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-index.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/1349837593565622785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7039237828665137460/posts/default/1349837593565622785'/><link rel='alternate' type='text/html' href='http://bluesky0215.blogspot.com/2021/11/python-index.html' title='Python-index使用'/><author><name>Jimmy 筆記</name><uri>http://www.blogger.com/profile/07501682047389761389</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgcuWwCvNhGCgLr5EnUKrF9p6YRJtsgM4eqafarU03H1wrQphbiI6C_S59c1841KpwWIDIZ56GYft89zYKibFieVtfsY9wF1xljKJbL7wrVtNw5cAkvkqOCdAROTOfHRSKFjJpZgASW9y3Vz8xCNClj536-VULqj_EIXnYMMI1Lm2B0PwzZ0ZDVFacB=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry></feed>