## 檔案路徑出錯問題
import os
# 當前檔案的完整路徑
print(__file__) #__file__表示了當前檔案的路徑
print(os.path.abspath(__file__)) #os.path.abspath功能返回乙個目錄的絕對路徑
print(os.path.realpath(__file__)) #os.path.realpath功能返回指定檔案的標準路徑,而非軟鏈結所在的路徑
# 兩者的差別是,當你用相對路徑執行該檔案時候,__file__的值是該相對路徑
# 所以推薦使用 os.path.abspath 和os.path.realpath,確保值為絕對路徑
# 當前檔案所處的資料夾的絕對路徑
print(os.path.dirname(os.path.abspath(__file__))) #os.path.dirname(path)功能是去掉檔名,返回目錄
print(os.path.dirname(os.path.realpath(__file__)))
print(os.path.abspath(os.path.split(__file__)[0]))
# 當前檔案所處的資料夾的上一級資料夾的絕對路徑
print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(os.path.abspath(os.path.split(os.path.split(__file__)[0])[0]))
# 當前執行空間的絕對路徑
print(os.path.abspath('.'))
# 當前執行空間的上一級資料夾的絕對路徑
print(os.path.abspath('..'))
""" 如何引入自己編寫的模組 """
import os,sys
from tool import tool
print(tool.sum(1,1))
""" 使用絕對路徑匯入,文字等資源 """
#當文字和本檔案在同一資料夾下可以這麼寫
os.path.join(os.path.dirname(os.path.abspath(__file__)), "a.txt")
""" 路徑的拼接 """
#路徑中最好使用雙斜桿 \\
import os
path1 = "e:\\pythonworkspace"
path2 = "test.txt"
path = os.path.join(path1, path2)
print(path)
""" 遍歷目錄下所有檔案 """
rootdir = 'f:\data'
list = os.listdir(rootdir)
for e in range(0,len(list)):
path = os.path.join(rootdir,list[i])
if os.path.isfile(path):
pass
查詢執行路徑
當希望 mysql 能夠以更高的效能進行查詢時,最好的辦法就是弄清楚 mysql 是如何進行優化和查詢的。一旦理解這一點,很多查詢優化工作實際上就是遵循一些原則讓優化器能夠按照預想的合理的方式執行。下圖顯示了 mysql 如何處理乙個使用者請求的過程。img 從圖中可見,它的處理過程大致是這樣的 1...
bat檔案 執行路徑
最近用到了bat的一些東西,就是用c 程式呼叫bat檔案時,bat檔案中的路徑怎樣動態的獲取呢?用 dp0 可以得到。比如要註冊乙個名為test.dll的檔案,dll檔案和bat檔案放在同乙個資料夾下 bat檔案寫法 regsvr32 dp0test.dll s 又比如要呼叫另外乙個bat檔案 檔名...
MySQL查詢執行路徑
mysql查詢執行路徑 1.客戶端傳送一條查詢給伺服器 2.伺服器先會檢查查詢快取,如果命中了快取,則立即返回儲存在快取中的結果。否則進入下一階段 3.伺服器端進行sql解析 預處理,再由優化器生成對應的執行計畫 4.mysql根據優化器生成的執行計畫,呼叫儲存引擎的api來執行查詢 5.將結果返回...