<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python | SDT 攻城獅區</title>
	<atom:link href="https://sdt.hameba.tw/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://sdt.hameba.tw</link>
	<description>由Steven, Der, Ted 三位高級打字員所組成，是三位工程師(攻城獅)所維護的技術分享平台，或許偶爾會分享一些日常，有任何問題或是錯誤的部分，歡迎留言告訴我們！</description>
	<lastBuildDate>Fri, 05 Aug 2022 16:45:13 +0800</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.3</generator>

<image>
	<url>https://sdt.hameba.tw/wp-content/uploads/2020/02/hameba_favicon-150x150.png</url>
	<title>Python | SDT 攻城獅區</title>
	<link>https://sdt.hameba.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>安裝Python以及安裝編輯器VSCode</title>
		<link>https://sdt.hameba.tw/663/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25e5%25ae%2589%25e8%25a3%259dpython%25e4%25bb%25a5%25e5%258f%258a%25e5%25ae%2589%25e8%25a3%259d%25e7%25b7%25a8%25e8%25bc%25af%25e5%2599%25a8vscode</link>
				<comments>https://sdt.hameba.tw/663/#respond</comments>
				<pubDate>Thu, 04 Aug 2022 16:57:12 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[VSCode]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=663</guid>
				<description><![CDATA[<p>Python是一種直譯語言，需要執行平台(runtime)。 Python官網可以直接下載Python3然後安 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/663/" class="more-link">閱讀全文<span class="screen-reader-text">〈安裝Python以及安裝編輯器VSCode〉</span></a></p>
The post <a href="https://sdt.hameba.tw/663/">安裝Python以及安裝編輯器VSCode</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>Python是一種直譯語言，需要執行平台(runtime)。</p>
<p><a href="https://www.python.org/downloads/" target="_blank" rel="noopener noreferrer">Python官網</a>可以直接下載Python3然後安裝。<em>(範例為Python 3.10.6)</em></p>
<p><span id="more-663"></span></p>
<p><span style="color: #ff0000"><strong>＊Python2已經不會再出新版本，已在2020/01/01停止官方支援</strong></span></p>
<p><img class="size-medium wp-image-666" src="https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadPython-300x199.png" alt="DownloadPython" width="300" height="199" srcset="https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadPython-300x199.png?v=1659630158 300w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadPython-1024x680.png?v=1659630158 1024w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadPython-768x510.png?v=1659630158 768w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadPython-1536x1020.png?v=1659630158 1536w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadPython-2048x1360.png?v=1659630158 2048w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>俗話說得好「工欲善其事，必先利其器」，接下來～</p>
<p>我們需要一個拿來寫程式的文字編輯器，讓我們來<a href="https://code.visualstudio.com/Download" target="_blank" rel="noopener noreferrer">下載VSCode</a>安裝。</p>
<p><img class="alignnone size-medium wp-image-667" src="https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadVSCode-300x177.png" alt="DownloadVSCode" width="300" height="177" srcset="https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadVSCode-300x177.png?v=1659630571 300w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadVSCode-1024x603.png?v=1659630571 1024w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadVSCode-768x452.png?v=1659630571 768w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadVSCode-1536x904.png?v=1659630571 1536w, https://sdt.hameba.tw/wp-content/uploads/2022/08/DownloadVSCode-2048x1205.png?v=1659630571 2048w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>安裝好VSCode後，讓我們把它打開來並且安裝延伸模組。</p>
<p>點選『延伸模組』並輸入python，會看到「Python」讓我們安裝它。</p>
<p><img class="alignnone size-medium wp-image-668" src="https://sdt.hameba.tw/wp-content/uploads/2022/08/VSCodePythonExtension-300x271.png" alt="VSCodePythonExtension" width="300" height="271" srcset="https://sdt.hameba.tw/wp-content/uploads/2022/08/VSCodePythonExtension-300x271.png?v=1659631911 300w, https://sdt.hameba.tw/wp-content/uploads/2022/08/VSCodePythonExtension-1024x924.png?v=1659631911 1024w, https://sdt.hameba.tw/wp-content/uploads/2022/08/VSCodePythonExtension-768x693.png?v=1659631911 768w, https://sdt.hameba.tw/wp-content/uploads/2022/08/VSCodePythonExtension-1536x1385.png?v=1659631911 1536w, https://sdt.hameba.tw/wp-content/uploads/2022/08/VSCodePythonExtension.png?v=1659631911 1662w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>這樣子我們都準備好，可以開始寫Python程式了！</p>
<blockquote><p>Python檔案的副檔名 .py</p></blockquote>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>參考資料：</p>
<p><a href="https://www.youtube.com/watch?v=CXZYvNRIAKM&amp;list=PLlrxD0HtieHhS8VzuMCfQD4uJ9yne1mE6&amp;index=3" target="_blank" rel="noopener noreferrer">Getting Started | Python for Beginners [3 of 44]</a></p>
<p><a href="https://www.youtube.com/watch?v=EU8eayHWoZg&amp;list=PLlrxD0HtieHhS8VzuMCfQD4uJ9yne1mE6&amp;index=4" target="_blank" rel="noopener noreferrer">Configuring Visual Studio Code | Python for Beginners [4 of 44]</a></p>
<p><a href="https://www.python.org/downloads/" target="_blank" rel="noopener noreferrer">Download Python</a></p>
<p><a href="https://code.visualstudio.com/Download" target="_blank" rel="noopener noreferrer">Download Visual Studio Code</a></p>The post <a href="https://sdt.hameba.tw/663/">安裝Python以及安裝編輯器VSCode</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/663/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>python 取得終端機指令</title>
		<link>https://sdt.hameba.tw/630/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e5%258f%2596%25e5%25be%2597%25e7%25b5%2582%25e7%25ab%25af%25e6%25a9%259f%25e6%258c%2587%25e4%25bb%25a4</link>
				<comments>https://sdt.hameba.tw/630/#respond</comments>
				<pubDate>Sat, 29 Feb 2020 15:42:47 +0000</pubDate>
		<dc:creator><![CDATA[Ted]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=630</guid>
				<description><![CDATA[<p>有時後在執行一些功能時，會習慣從終端機直接帶一些參數，好取得特定的資料，那python 程式碼要如何取得終端機 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/630/" class="more-link">閱讀全文<span class="screen-reader-text">〈python 取得終端機指令〉</span></a></p>
The post <a href="https://sdt.hameba.tw/630/">python 取得終端機指令</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>有時後在執行一些功能時，會習慣從終端機直接帶一些參數，好取得特定的資料，那python 程式碼要如何取得終端機的指令？</p>
<p><span id="more-630"></span></p>
<p>很簡單，只要使用 python 標準函式庫 sys 模組裡的 <code>argv</code> 變數就可以了。</p><pre class="crayon-plain-tag"># 範例程式碼
# 只要在終端機輸入：<span class="pre">python</span> <span class="pre">demo.py</span> <span class="pre">one</span> two<span class="pre">
</span>
&gt;&gt;&gt; import sys
&gt;&gt;&gt; print(sys.argv)
['demo.py', 'one', 'two']</pre><p>如果要更為複雜的使用終端機輸入的指令的話，可以使用  sys 模組裡的 <a class="reference internal" title="argparse: Command-line option and argument parsing library." href="https://docs.python.org/zh-tw/3/library/argparse.html#module-argparse"><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> 變數。</p>
<p>參考文件</p>
<p><a href="https://docs.python.org/zh-tw/3/tutorial/stdlib.html">https://docs.python.org/zh-tw/3/tutorial/stdlib.html</a></p>The post <a href="https://sdt.hameba.tw/630/">python 取得終端機指令</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/630/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Python初學者教學影片</title>
		<link>https://sdt.hameba.tw/606/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python%25e5%2588%259d%25e5%25ad%25b8%25e8%2580%2585%25e6%2595%2599%25e5%25ad%25b8%25e5%25bd%25b1%25e7%2589%2587</link>
				<comments>https://sdt.hameba.tw/606/#respond</comments>
				<pubDate>Fri, 28 Feb 2020 16:29:46 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=606</guid>
				<description><![CDATA[<p>＃＃ 2022/08/05 更新  (持續更新中)＃＃ 學習任何一種新的語言時， 最大的障礙可能就是不知道從哪 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/606/" class="more-link">閱讀全文<span class="screen-reader-text">〈Python初學者教學影片〉</span></a></p>
The post <a href="https://sdt.hameba.tw/606/">Python初學者教學影片</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>＃＃ <strong>2022/08/05 更新  (持續更新中)</strong>＃＃</p>
<p>學習任何一種新的語言時，</p>
<p>最大的障礙可能就是不知道從哪裡開始。</p>
<p><span id="more-606"></span></p>
<p>微軟有推出Python程式語言的教學影片。</p>
<p>總共有44支影片，長度最長的也只有12分鐘。</p>
<p><iframe title="Python for Beginners" width="525" height="295" src="https://www.youtube.com/embed/videoseries?list=PLlrxD0HtieHhS8VzuMCfQD4uJ9yne1mE6" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<p><del>有機會再分享影片中各個章節！</del></p>
<p>分享各個章節的重點部分：</p>
<p><strong>第1章節 &#8211; 講師介紹 (Susan Ibach &amp; Christopher Harrison)</strong></p>
<p><strong>第2章節 &#8211; 什麼是Python? 為什麼選Python? Python可以做什麼?</strong></p><pre class="crayon-plain-tag">彈性高、靈活、可讀性高的程式語言，不需要記太多語法、字元、符號。

機器學習模型、AI專案、網頁應用程式、自動化腳本和工具。(幾乎都能做)

更棒的是，有很多套件可以下載，再加入自己的邏輯即可完成想要的程式</pre><p><strong>第3, 4章節 &#8211; 開始安裝Python以及安裝編輯器VSCode</strong></p>
<p><a href="https://sdt.hameba.tw/663/#more-663" target="_blank" rel="noopener noreferrer">安裝Python以及安裝編輯器VSCode | SDT 攻城獅區</a></p>
<p><strong>第5至16章節 &#8211; 簡單實做，如何輸出、寫註解、字串、數字、日期</strong></p>
<p>(趕工中，敬請期待..)</p>
<p>&nbsp;</p>The post <a href="https://sdt.hameba.tw/606/">Python初學者教學影片</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/606/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Python 使用 pytube 下載 Youtube 影片</title>
		<link>https://sdt.hameba.tw/511/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e4%25bd%25bf%25e7%2594%25a8-pytube-%25e4%25b8%258b%25e8%25bc%2589-youtube-%25e5%25bd%25b1%25e7%2589%2587</link>
				<comments>https://sdt.hameba.tw/511/#respond</comments>
				<pubDate>Mon, 03 Feb 2020 17:04:14 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[pytube]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=511</guid>
				<description><![CDATA[<p>現在 Youtube 越來越方便，有時候我們會想要把影片下載下來， 這時候就可以使用 pytube 模組。 首 &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/511/" class="more-link">閱讀全文<span class="screen-reader-text">〈Python 使用 pytube 下載 Youtube 影片〉</span></a></p>
The post <a href="https://sdt.hameba.tw/511/">Python 使用 pytube 下載 Youtube 影片</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>現在 Youtube 越來越方便，有時候我們會想要把影片下載下來，</p>
<p>這時候就可以使用 pytube 模組。</p>
<p><span id="more-511"></span></p>
<p>首先要先安裝 pytube 的模組，詳細資訊的話，可以去開發者的 <a href="https://github.com/nficano/pytube">Github</a> 瞧瞧。</p><pre class="crayon-plain-tag">pip3 install pytube</pre><p><img class="alignnone wp-image-512 size-full" src="https://sdt.hameba.tw/wp-content/uploads/2020/02/install_pytube.png" alt="install_pytube" width="802" height="142" srcset="https://sdt.hameba.tw/wp-content/uploads/2020/02/install_pytube.png?v=1580749153 802w, https://sdt.hameba.tw/wp-content/uploads/2020/02/install_pytube-300x53.png?v=1580749153 300w, https://sdt.hameba.tw/wp-content/uploads/2020/02/install_pytube-768x136.png?v=1580749153 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></p>
<p>安裝的版本為 <span style="color: #0000ff">pytube-9.5.3</span></p>
<p>接下來，快速簡單的示範如何下載影片。</p>
<p>拿這個網址做示範：<a href="https://www.youtube.com/watch?v=dq-1hVpnquk">https://www.youtube.com/watch?v=dq-1hVpnquk</a></p><pre class="crayon-plain-tag">from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=dq-1hVpnquk')
yt.streams.first().download()</pre><p>執行後過一會就會出現啦。(影片會跟程式在同一層目錄)</p>
<p>如果出現錯誤訊息 <span style="color: #ff0000">KeyError: &#8216;url_encoded_fmt_stream_map&#8217;</span></p>
<p>可以參考 <a href="https://github.com/nficano/pytube/issues/467">Issue</a> 來排除 (把mixins.py裡apply_descrambler中的內容替換)</p>
<p>最後，提醒大家下載的影片僅供個人使用或學術交流，避免做商業用途。</p>
<p>&nbsp;</p>
<p>參考資料·：</p>
<p><a href="https://python-pytube.readthedocs.io/en/latest/">https://python-pytube.readthedocs.io/en/latest/</a></p>The post <a href="https://sdt.hameba.tw/511/">Python 使用 pytube 下載 Youtube 影片</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/511/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>python 使用 MongoDB 基本集合(CRUD)</title>
		<link>https://sdt.hameba.tw/452/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e4%25bd%25bf%25e7%2594%25a8-mongodb-%25e5%259f%25ba%25e6%259c%25ac%25e9%259b%2586%25e5%2590%2588crud</link>
				<comments>https://sdt.hameba.tw/452/#respond</comments>
				<pubDate>Sun, 05 Jan 2020 14:45:29 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pymongo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=452</guid>
				<description><![CDATA[<p>先前介紹了使用pymongo來連線MongoDB，以及驗證身份來做連線。 這次來說明基本的集合(CRUD)。  &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/452/" class="more-link">閱讀全文<span class="screen-reader-text">〈python 使用 MongoDB 基本集合(CRUD)〉</span></a></p>
The post <a href="https://sdt.hameba.tw/452/">python 使用 MongoDB 基本集合(CRUD)</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>先前介紹了使用pymongo來連線MongoDB，以及驗證身份來做連線。</p>
<p>這次來說明基本的集合(CRUD)。</p>
<p><span id="more-452"></span></p>
<ul>
<li><strong>起手式</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">from pymongo import MongoClient

client = MongoClient('YOUR_DB_IP', 27017)
db = client[MONGO_DB]
db.authenticate(MONGO_USER_NAME, MONGO_USER_PWD)
collection = db[MONGO_COLLETION]</pre><p>&nbsp;</p>
<ul>
<li><strong>查詢資料｜單筆(find_one)｜全部(find)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.find_one({'x': 1}) #查詢符合資料的第一筆</pre><p></p><pre class="crayon-plain-tag">collection.find({'x': 1}) #查詢符合資料的全部</pre><p>&nbsp;</p>
<ul>
<li><strong>查詢個數｜(<span class="n">count_documents</span>)</strong></li>
</ul>
<div>
<pre class="crayon-plain-tag">collection.count_documents({'x': 1}) #查詢符合資料的個數</pre>
</div>
<p>&nbsp;</p>
<ul>
<li><strong>寫入資料｜單筆(insert_one)｜多筆(insert_many)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.insert_one({'x': 1}) #一次新增一筆資料</pre><p></p><pre class="crayon-plain-tag">collection.insert_many([{'x': 1},{'x': 1}]) #一次新增多筆資料</pre><p>&nbsp;</p>
<ul>
<li><strong>修改資料｜單筆(update_one)｜多筆(update_many)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.update_one({'x': 1}, {'$set': {'x': 2}}) #修改符合資料的第一筆</pre><p></p><pre class="crayon-plain-tag">collection.update_many({'x': 1}, {'$set': {'x': 2}}) #修改符合資料的全部</pre><p>&nbsp;</p>
<ul>
<li><strong>刪除資料｜單筆(delete_one)｜多筆(delete_many)</strong></li>
</ul>
<p></p><pre class="crayon-plain-tag">collection.delete_one({'x': 1}) #刪除符合的第一筆資料</pre><p></p><pre class="crayon-plain-tag">collection.delete_many({'x': 1}) #刪除符合的全部資料</pre><p>&nbsp;</p>
<p>&nbsp;</p>
<p>參考資料：</p>
<ol>
<li><a href="https://api.mongodb.com/python/current/api/pymongo/collection.html">https://api.mongodb.com/python/current/api/pymongo/collection.html</a></li>
<li><a href="https://www.jianshu.com/p/2b176830ca1e">https://www.jianshu.com/p/2b176830ca1e</a></li>
</ol>
<p>&nbsp;</p>The post <a href="https://sdt.hameba.tw/452/">python 使用 MongoDB 基本集合(CRUD)</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/452/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Python 連線 MongoDB 驗證身份</title>
		<link>https://sdt.hameba.tw/385/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e9%2580%25a3%25e7%25b7%259a-mongodb-%25e9%25a9%2597%25e8%25ad%2589%25e8%25ba%25ab%25e4%25bb%25bd</link>
				<comments>https://sdt.hameba.tw/385/#respond</comments>
				<pubDate>Sun, 29 Dec 2019 15:12:04 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[authenticate]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pymongo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=385</guid>
				<description><![CDATA[<p>上一次有提到  Python 連線 MongoDB ， 這次來補充如果要驗證身份的話，要怎麼處理。 首先在Mo &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/385/" class="more-link">閱讀全文<span class="screen-reader-text">〈Python 連線 MongoDB 驗證身份〉</span></a></p>
The post <a href="https://sdt.hameba.tw/385/">Python 連線 MongoDB 驗證身份</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>上一次有提到  <a href="https://sdt.hameba.tw/367/" target="_blank" rel="noopener noreferrer">Python 連線 MongoDB</a> ，</p>
<p>這次來補充如果要驗證身份的話，要怎麼處理。</p>
<p><span id="more-385"></span></p>
<p>首先在MongoDB建立一個使用者，</p>
<p>設定好使用者名稱、密碼、角色。</p>
<p>再來看一下程式要怎麼調整：</p>
<div>
<div>
<pre class="crayon-plain-tag">client = MongoClient('YOUR_DB_IP', 27017)
db = client[MONGO_DB]
db.authenticate(MONGO_USER_NAME, MONGO_USER_PWD)</pre>
</div>
<p>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p>參考資料：</p>
<p><a href="https://api.mongodb.com/python/current/examples/authentication.html">https://api.mongodb.com/python/current/examples/authentication.html</a></p>The post <a href="https://sdt.hameba.tw/385/">Python 連線 MongoDB 驗證身份</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/385/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Python 連線 MongoDB ( pymongo )</title>
		<link>https://sdt.hameba.tw/367/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-%25e9%2580%25a3%25e7%25b7%259a-mongodb-pymongo</link>
				<comments>https://sdt.hameba.tw/367/#respond</comments>
				<pubDate>Sun, 22 Dec 2019 15:47:12 +0000</pubDate>
		<dc:creator><![CDATA[Li Der]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[pymongo]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">https://sdt.hameba.tw/?p=367</guid>
				<description><![CDATA[<p>先安裝好MongoDB， 接下來我們在安裝 pymongo，就可以連線MongoDB了。 先用 pip 安裝  &#8230; </p>
<p class="link-more"><a href="https://sdt.hameba.tw/367/" class="more-link">閱讀全文<span class="screen-reader-text">〈Python 連線 MongoDB ( pymongo )〉</span></a></p>
The post <a href="https://sdt.hameba.tw/367/">Python 連線 MongoDB ( pymongo )</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></description>
								<content:encoded><![CDATA[<p>先安裝好MongoDB，</p>
<p>接下來我們在安裝 pymongo，就可以連線MongoDB了。</p>
<p><span id="more-367"></span></p>
<p>先用 pip 安裝 pymongo</p><pre class="crayon-plain-tag">pip3 install pymongo</pre><p>記得要先import</p><pre class="crayon-plain-tag">from pymongo import MongoClient</pre><p>連線MongoDB</p><pre class="crayon-plain-tag">global collection
client = MongoClient('YOUR_DB_IP', 27017)
db = client[MONGO_DB]
collection = db[MONGO_COLLETION]</pre><p>如何 <a href="https://sdt.hameba.tw/385/" target="_blank" rel="noopener noreferrer">Python 連線 MongoDB 驗證身份</a></p>
<p>&nbsp;</p>
<p>參考資料：</p>
<p><a href="https://www.itread01.com/content/1547079438.html">https://www.itread01.com/content/1547079438.html</a></p>The post <a href="https://sdt.hameba.tw/367/">Python 連線 MongoDB ( pymongo )</a> first appeared on <a href="https://sdt.hameba.tw">SDT 攻城獅區</a>.]]></content:encoded>
							<wfw:commentRss>https://sdt.hameba.tw/367/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
	</channel>
</rss>
