2012-08-01 28 views

Trả lời

46

Sử dụng os.path.dirname(filename).

1

Kiểm tra tàu ngầm của os.path

os.path.dirname('/test/one') 
5

Bạn có thể import os

>>> filepath 
'/a/path/to/my/file.txt' 
>>> os.path.dirname(filepath) 
'/a/path/to/my' 
>>> 
2
(dirname, filename) = os.path.split(path) 
+0

chính xác hơn: '(nghỉ ngơi, first_path_item) = os.path.split (đường dẫn)' – estani

Các vấn đề liên quan