[Tutor] character format

Chris Smith smichr at bigfoot.com
Thu May 12 05:34:33 CEST 2005


On Wednesday, May 11, 2005, at 20:43 America/Chicago,  
tutor-request at python.org wrote:

> I believe Max's guess was that the file is compressed with bzip (the  
> first
> two characters will be BZ, as you found).  Try doing:
>
>>>> import bz2
>>>> print bz2.decompress(data)
>
> Where data is a string containing the characters you have.  (Although  
> you
> say that compression is unlikely, the BZ characters would be a big
> co-incidence).
>

That interactive mode is *very* helpful.  If you import a module and  
then do a directory on it to see what it has for "tools" and then start  
playing with them, you can learn some interesting things without a lot  
of overhead:

###
 >>> import bz2
 >>> dir(bz2)
['BZ2Compressor', 'BZ2Decompressor', 'BZ2File', '__author__',  
'__doc__', '__file__', '__name__', 'compress', 'decompress']
 >>> bz2.compress('foo')
"BZh91AY&SYI\xfe\xc4\xa5\x00\x00\x00\x01\x00\x01\x00\xa0\x00!\x00\x82,]\ 
xc9\x14\xe1BA'\xfb\x12\x94"
 >>> bz2.decompress(_) #underscore to reference last thing
'foo'
###

Hmmm...

/c



More information about the Tutor mailing list