Update documentation for Python 3

This commit is contained in:
Martin Panter 2014-01-18 07:35:50 +00:00
parent a6fd013a77
commit 704ed76229

View File

@ -12,7 +12,7 @@ WARNING: THIS IS (STILL) WORK IN PROGRESS.
Main improvements over PIL version of OleFileIO: Main improvements over PIL version of OleFileIO:
------------------------------------------------ ------------------------------------------------
- Better compatibility with Python 2.4 up to 2.7 - Better compatibility with Python 2.7 (also compatible with Python 3.2+)
- Support for files larger than 6.8MB - Support for files larger than 6.8MB
- Robust: many checks to detect malformed files - Robust: many checks to detect malformed files
- Improved API - Improved API
@ -57,28 +57,28 @@ Here are a few examples:
ole = OleFileIO_PL.OleFileIO('myfile.doc') ole = OleFileIO_PL.OleFileIO('myfile.doc')
# Get list of streams: # Get list of streams:
print ole.listdir() print(ole.listdir())
# Test if known streams/storages exist: # Test if known streams/storages exist:
if ole.exists('worddocument'): if ole.exists('worddocument'):
print "This is a Word document." print("This is a Word document.")
print "size :", ole.get_size('worddocument') print("size :", ole.get_size('worddocument'))
if ole.exists('macros/vba'): if ole.exists('macros/vba'):
print "This document seems to contain VBA macros." print("This document seems to contain VBA macros.")
# Extract the "Pictures" stream from a PPT file: # Extract the "Pictures" stream from a PPT file:
if ole.exists('Pictures'): if ole.exists('Pictures'):
pics = ole.openstream('Pictures') pics = ole.openstream('Pictures')
data = pics.read() data = pics.read()
f = open('Pictures.bin', 'w') f = open('Pictures.bin', 'wb')
f.write(data) f.write(data)
f.close() f.close()
# Extract metadata (new in v0.24) - see source code for all attributes: # Extract metadata (new in v0.24) - see source code for all attributes:
meta = ole.get_metadata() meta = ole.get_metadata()
print 'Author:', meta.author print('Author:', meta.author)
print 'Title:', meta.title print('Title:', meta.title)
print 'Creation date:', meta.create_time print('Creation date:', meta.create_time)
# print all metadata: # print all metadata:
meta.dump() meta.dump()
@ -87,9 +87,9 @@ Here are a few examples:
# Work with a file-like object (e.g. StringIO) instead of a file on disk: # Work with a file-like object (e.g. StringIO) instead of a file on disk:
data = open('myfile.doc', 'rb').read() data = open('myfile.doc', 'rb').read()
f = StringIO.StringIO(data) f = io.BytesIO(data)
ole = OleFileIO_PL.OleFileIO(f) ole = OleFileIO_PL.OleFileIO(f)
print ole.listdir() print(ole.listdir())
ole.close() ole.close()