[問題] 關於絕對路徑。
各位先進好:請教有關絕對路徑的問題,程式碼如下。
import os
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
rel_path = "\html\9498886.html"
abs_file_path = script_dir+rel_path
abs_file_path2 = os.path.join(script_dir, rel_path)
檔案放在以下目錄。
D:\ides13\OneDrive\ipycode\claimsim\vx15
我使用「abs_file_path2 = os.path.join(script_dir, rel_path)」時,
abs_file_path2之變數的值是:「D:\html\9498886.html」
但是「abs_file_path = script_dir+rel_path」的值,卻是正確的。
請問我什麼地方做錯了?是什麼原因造成這兩種差異?謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.133.32.131 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1595392225.A.839.html
推
07/22 12:48,
5年前
, 1F
07/22 12:48, 1F
→
07/22 12:48,
5年前
, 2F
07/22 12:48, 2F
→
07/22 12:49,
5年前
, 3F
07/22 12:49, 3F
→
07/22 13:08,
5年前
, 4F
07/22 13:08, 4F
→
07/22 18:32,
5年前
, 5F
07/22 18:32, 5F
Python 近期熱門文章
PTT數位生活區 即時熱門文章