[Python] 絶対パスからディレクトリ部分を抽出する

■やりたいこと
/home/hoge/work/mydocument.txt というような絶対パスで表されたファイル名からディレクトリ部分を抜き出す。
この場合、/home/hoge/workが取り出せればよい。

■サンプルプログラム

import os

f = '/home/hoge/work/mydocument.txt'
dir_part = os.path.dirname(f)