2012-08-01 2 views

답변

46

사용 os.path.dirname(filename)없이 .split()을 시도>/a/path/to/my/

-/a/path/to/my/file.txt 같은

뭔가. os.path

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

확인 잠수정 할 수 있습니다 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

더 정확하게'(나머지 first_path_item) = os.path.split (경로)' – estani