-
-
Save zooid/79df4ccaccd121eb202d9b54d54a10f2 to your computer and use it in GitHub Desktop.
Learning to use Python zipfile module with docx files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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