Skip to content

Instantly share code, notes, and snippets.

@JGVerdugo
Created November 8, 2012 03:38
Show Gist options
  • Save JGVerdugo/4036588 to your computer and use it in GitHub Desktop.
Save JGVerdugo/4036588 to your computer and use it in GitHub Desktop.
Learning to use Python zipfile module with docx files
#!/usr/bin/python
import os
import os.path
import zipfile
from datetime import datetime
from re import sub
sourceFile = zipfile.ZipFile('text.docx')
list = sourceFile.namelist()
publicDir = os.getenv("TMP")
timestamp = datetime.now().isoformat()
timestamp = sub("[:.]", "", timestamp)
dirname = "xtemp-jgv-" + timestamp
tempDir = os.path.join(publicDir, dirname)
os.mkdir(tempDir)
sourceFile.extractall(tempDir)
documentPath = os.path.join(tempDir, "word")
document = open(os.path.join(documentPath, "document.xml"), "a+")
document.seek(2666)
print document.read(466)
print document.tell()
sourceFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment