Tôi muốn lấy đường dẫn của thư mục hiện tại, theo đó một tệp .py được thực thi.
Ví dụ: một tệp đơn giản D:\test.py
có mã:
import os
print os.getcwd()
print os.path.basename(__file__)
print os.path.abspath(__file__)
print os.path.dirname(__file__)
Điều kỳ lạ là đầu ra là:
D:\
test.py
D:\test.py
EMPTY
Tôi đang mong đợi kết quả tương tự từ getcwd()
và path.dirname()
.
Cho os.path.abspath = os.path.dirname + os.path.basename
, tại sao
os.path.dirname(__file__)
Trả về sản phẩm nào?