#範例11-2:使用模組module:使用另外一個檔案student.py裡面的dict變數stu #(在colab虛擬專案目錄測試) #https://www.w3schools.com/python/python_modules.asp #https://www.w3school.com.cn/python/python_try_except.asp #https://www.w3school.com.cn/python/python_modules.asp #如何讀取cola虛擬專案目錄裡面的檔案(暫存幾天),影片教學 #https://www.youtube.com/watch?v=_v-PIMyh2t8 #如何讀取colabgoogle雲端硬碟drive的檔案(永遠保存),影片教學 #https://www.youtube.com/watch?v=20BTlpVVETw&list=PLI4GrHDZHd1b929fSmjrdBwXE2IjP0dF6&index=2 #觀念: #(1)什麼是module:模組是包含函數/變數的檔案,可以被其它的應用程式引用這個mudule的函數/變數。 #(2)先建立student.py,裡面有個dict變數stu #(3)在bs-11-2.py裡面,import stu,然後查詢前三位同學姓名 #--------------- #1.練習:讀取colab虛擬專案目錄的student.py裡面的dict變數stu #(1)先在左邊的『檔案』 #(2)建立新的筆記本(建立 stu = {"a01":"john","a02":"tom","a03":"mike"} #(3)下載student.py到電腦的硬碟(方法:檔案-->下載-->格式,選擇.py) #(4)上傳student.py到colab虛擬專案目錄(左上角的上傳icon) # 注意:不是student.ipynb,而是student.py #(5)建立bs-11-2檔案(開新筆記本) #(6)import student #印出第1位同學= student.stu["a01"] #注意:這個練習,都是在colab的虛擬專案目錄裡面測試,google幾天後就會把測試檔案刪除了 #------------------------------ #1.練習1:import student print("第1位同學=") print("第2位同學=") print("第3位同學=") #------------------------------ #2.練習2:from student import stu print() print("第1位同學=") print("第2位同學=") print("第3位同學=") #------------------------------ #3.練習3:from student import stu as s1 print() print("第1位同學=") print("第2位同學=") print("第3位同學=") #----------------------------------------------------- #----------------------------------------------------- #範例11-2:使用模組module:使用另外一個檔案student.py裡面的dict變數stu #(在colab虛擬專案目錄測試) #https://www.w3schools.com/python/python_modules.asp #https://www.w3school.com.cn/python/python_try_except.asp #https://www.w3school.com.cn/python/python_modules.asp #如何讀取cola虛擬專案目錄裡面的檔案(暫存幾天),影片教學 #https://www.youtube.com/watch?v=_v-PIMyh2t8 #如何讀取colabgoogle雲端硬碟drive的檔案(永遠保存),影片教學 #https://www.youtube.com/watch?v=20BTlpVVETw&list=PLI4GrHDZHd1b929fSmjrdBwXE2IjP0dF6&index=2 #觀念: #(1)什麼是module:模組是包含函數/變數的檔案,可以被其它的應用程式引用這個mudule的函數/變數。 #(2)先建立student.py,裡面有個dict變數stu #(3)在bs-11-2.py裡面,import stu,然後查詢前三位同學姓名 #--------------- #1.練習:讀取colab虛擬專案目錄的student.py裡面的dict變數stu #(1)先在左邊的『檔案』 #(2)建立新的筆記本(建立 stu = {"a01":"john","a02":"tom","a03":"mike"} #(3)下載student.py到電腦的硬碟(方法:檔案-->下載-->格式,選擇.py) #(4)上傳student.py到colab虛擬專案目錄(左上角的上傳icon) # 注意:不是student.ipynb,而是student.py #(5)建立bs-11-2檔案(開新筆記本) #(6)import student #印出第1位同學= student.stu["a01"] #注意:這個練習,都是在colab的虛擬專案目錄裡面測試,google幾天後就會把測試檔案刪除了 #------------------------------ #1.練習1:import student import student print("第1位同學=", student.stu["a01"]) print("第2位同學=", student.stu["a02"]) print("第3位同學=", student.stu["a03"]) #------------------------------ #2.練習2:from student import stu print() from student import stu print("第1位同學=", student.stu["a01"]) print("第2位同學=", student.stu["a02"]) print("第3位同學=", student.stu["a03"]) #------------------------------ #3.練習3:from student import stu as s1 print() from student import stu as s1 print("第1位同學=", s1["a01"]) print("第2位同學=", s1["a02"]) print("第3位同學=", s1["a03"]) #-----------------------------------------------------