title: Unzipping a .docx file using zipfile library
body: <p>I am trying write an application gets information from a table in a word docx file in order to do some analysis on it by putting turning it into a pandas <code>DataFrame</code>. The first step is properly reading and the docx file, and to do this, I am following Virantha Ekanayake's guide for <a href="https://virantha.com/2013/08/16/reading-and-writing-microsoft-word-docx-files-with-python/" rel="nofollow noreferrer">Reading and writing Microsoft Word docx files with Python</a>.</p>
  <p>I'm at the first step where they say to use the <code>Zipfile</code> method of the <code>zipfile</code> library in order to unzip the docx file into xml files. I adapted the function definitions in the guide into my code (code included below), but when I run my code, I get an error saying that the docx file is &quot;not a zip file&quot;.</p>
  <p>This person in the guide says that, &quot;At its heart, a docx file is just a zip file (try running unzip on it!)…&quot; I have tried renaming the docx file to a zip file, and it successfully unzips using WinZip. In my program, however, I want to be able to unzip the docx file without having to rename it to a <code>.zip</code> file <strong>manually</strong>. Am I able somehow to unzip the docx file without renaming it? <em><strong>Or</strong></em>, if I have to rename it in order to use the <code>Zipfile</code> method, how do I do this in my python code?</p>
  <pre class="lang-py prettyprint-override"><code>import zipfile
  from lxml import etree
  import pandas as pd
  
  FILE_PATH = 'C:/Users/user/Documents/Python Project'
  
  class Application():
      def __init__(self):
          #debug print('Initialized!')
          xml_content = self.get_word_xml(f'{FILE_PATH}/DocxFile.docx') 
          xml_tree = self.get_xml_tree(xml_content)
  
      def get_word_xml(self, docx_filename):
          with open(docx_filename) as f:
              zip = zipfile.ZipFile(f)
              xml_content = zip.read('word/document.xml')
          return xml_content
  
      def get_xml_tree(self, xml_string):
          return (etree.fromstring(xml_string))
  
  a = Application()
  a.mainloop()
  
  </code></pre>
  <p>Error:</p>
  <pre class="lang-sh prettyprint-override"><code>Traceback (most recent call last):
  File &quot;C:\Users\user\Documents\New_Tool.py&quot;, line 39, in &lt;module&gt;
  a = Application()
  File &quot;C:\Users\user\Documents\New_Tool.py&quot;, line 27, in __init__
  xml_content = self.get_word_xml(f'{FILE_PATH}/DocxFile.docx')
  File &quot;C:\Users\user\Documents\New_Tool.py&quot;, line 32, in get_word_xml
  zip = zipfile.ZipFile(f)
  File &quot;C:\Progra~1\Anaconda3\lib\zipfile.py&quot;, line 1222, in __init__
  self._RealGetContents()
  File &quot;C:\Progra~1\Anaconda3\lib\zipfile.py&quot;, line 1289, in _RealGetContents
  raise BadZipFile(&quot;File is not a zip file&quot;)
  zipfile.BadZipFile: File is not a zip file
  </code></pre>