ฉันต้องการรับพา ธ ของไดเรกทอรีปัจจุบันภายใต้ไฟล์. py ที่ถูกเรียกใช้งาน
ตัวอย่างเช่นไฟล์อย่างง่ายD:\test.pyพร้อมรหัส:
import os
print os.getcwd()
print os.path.basename(__file__)
print os.path.abspath(__file__)
print os.path.dirname(__file__)
มันแปลกที่ผลลัพธ์คือ:
D:\
test.py
D:\test.py
EMPTY
ฉันคาดหวังว่าผลเดียวกันจากและgetcwd()path.dirname()
ให้os.path.abspath = os.path.dirname + os.path.basenameไว้ทำไม
os.path.dirname(__file__)
ผลตอบแทนที่ว่างเปล่า?