Python: abspath, basename, dirname

This is a note-to-self post regarding three of Python’s os.path functions, some examples:

>>> os.path.abspath('/opt/stuff/things/bin')
'/opt/stuff/things/bin'
>>> os.path.abspath('stuff/things/bin')
'/opt/stuff/things/bin'
>>> os.path.basename('/opt/stuff/things/bin')
'bin'
>>> os.path.dirname('/opt/stuff/things/bin')
'/opt/stuff/things'
  • email
  • PDF
  • Google Bookmarks
  • Yahoo! Bookmarks
  • del.icio.us
  • Twitter
  • Reddit
  • Digg
  • Ping.fm
  • Slashdot
  • Facebook
  • MySpace
  • Technorati
  • NewsVine
  • Tumblr
  • StumbleUpon

Leave a Reply