title: How to list only top level directories in Python?
body: <p>I want to be able to list only the directories inside some folder.
  This means I don't want filenames listed, nor do I want additional sub-folders.</p>
  
  <p>Let's see if an example helps. In the current directory we have:</p>
  
  <pre><code>&gt;&gt;&gt; os.listdir(os.getcwd())
  ['cx_Oracle-doc', 'DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'mod_p
  ython-wininst.log', 'NEWS.txt', 'pymssql-wininst.log', 'python.exe', 'pythonw.ex
  e', 'README.txt', 'Removemod_python.exe', 'Removepymssql.exe', 'Scripts', 'tcl',
   'Tools', 'w9xpopen.exe']
  </code></pre>
  
  <p>However, I don't want filenames listed. Nor do I want sub-folders such as \Lib\curses. Essentially what I want works with the following:</p>
  
  <pre><code>&gt;&gt;&gt; for root, dirnames, filenames in os.walk('.'):
  ...     print dirnames
  ...     break
  ...
  ['cx_Oracle-doc', 'DLLs', 'Doc', 'include', 'Lib', 'libs', 'Scripts', 'tcl', 'Tools']
  </code></pre>
  
  <p>However, I'm wondering if there's a simpler way of achieving the same results. I get the impression that using os.walk only to return the top level is inefficient/too much.</p>