เพื่อหาพาธเต็มของไฟล์ปัจจุบัน ให้ใช้ os.path.abspath(__file__) หากต้องการเฉพาะพาธไดเรกทอรี ให้ใช้ os.path.dirname
ตัวอย่าง
import os
absolute_path = os.path.abspath(__file__)
print("Full path: " + absolute_path)
print("Directory Path: " + os.path.dirname(absolute_path))
ผลลัพธ์
Full path: C:\python27\test.py Directory path: C:\python27\