--- title: 2 tags: 基礎Python-蘇柏原, 筆記 --- print(sys. argv) 取得路徑 windows:cmd 終端機 執行:python +檔名 #載入模組 ``` import sys as p print(p.argv) for d in p.argv: print("參數:", d) from sys import argv for d in argv: print("參數",d) 執行cmd指令 dir 看磁碟裡面的內容 cmd顯示的路徑是當前的工作路徑 cd 接路徑名稱 cls 清空畫面(windows) tasklist電腦裡面執行哪些程式 os.system (os是模組名稱) import os os.system("dir") os. system("tasklist") p=os.popen("tasklist") r=p.read print(r) if "notepad.exe" in r: print("現在有開啟記事本") else: print("沒有開啟記事本") ``` ---- #### windows 程式檔名 從工作管理員去看比較快 ** 作業:呼叫預設瀏覽器 windows 查詢預設瀏覽器 設定 應用程式與功能 左邊預設應用程式 編碼 big 5 編碼 utf-8 p.53 二進位、圖片 影片檔案 開啟檔案 可以不用指定編碼 因為裡面沒有文字 覆蓋w 都是寫入 覆蓋之前的 附加a 都是寫入 附加資料 影片 若沒關閉檔案 會佔用資源 d=os.listdir(.) 取得現在路徑 for d in os.listdir("."): print(d) ("./")當前資歷夾 ("../")回上一層 ("../..")回上上層 ("hw/")下層 執行路徑 會是工作路徑 取得當前工作路徑:os.getcwd() windows遇到斜線紫色時 有兩種解決:一種是更改斜線方向 另一個是變成兩條斜線