title: unzip extract in python
body: <p>i am using below code to extract files as below, but i see additional folder being created, could some one please help me why extra folder is being created.</p>
  
  <p>my file is as abc.zip which contains file sql.db,so ideally i need folder file as abc/sql.db but when i extract using below code i get folder as acb/abc/sql.db, why am i getting this extra folder being created</p>
  
  <pre><code>def unzip_artifact( local_directory, file_path ):
      fileName, ext = os.path.splitext( file_path )
      if ext == ".zip":
          print 'unzipping file ' + basename(fileName) + ext
          try:
              with zipfile.ZipFile(file_path) as zf:
                  for member in zf.infolist():
                          # Path traversal defense copied from
                          # http://hg.python.org/cpython/file/tip/Lib/http/server.py#l789
                          words = member.filename.split('/')
                          path = local_directory
                          for word in words[:-1]:
                              drive, word = os.path.splitdrive(word)
                              head, word = os.path.split(word)
                              if word in (os.curdir, os.pardir, ''): continue
                              path = os.path.join(path, word)             
                          zf.extract(member, path)
  
          except zipfile.error, e:
              print "Bad zipfile: %s" % (e)
          return
  </code></pre>