2011-08-24 40 views

Trả lời

16

http://docs.python.org/library/os.path.html

os.path.relpath (đường dẫn [, bắt đầu]) Quay trở lại một người họ hàng filepath đến đường dẫn hoặc từ thư mục hiện tại hoặc từ điểm bắt đầu tùy chọn.

bắt đầu mặc định là os.curdir.

Tính khả dụng: Windows, Unix.

Tính năng mới trong phiên bản 2.6.

16
>>> subdir1 = "live/events/livepkgr/events/_definst_/" 
>>> subdir2 = "live/streams/livepkgr/streams/_definst_/" 
>>> import os 
>>> os.path.relpath(subdir2, subdir1) 
'../../../../streams/livepkgr/streams/_definst_' 
>>> 
Các vấn đề liên quan