Newbie - unslicable type error etc

Emile van Sebille emile at fenx.com
Wed Oct 10 17:04:12 EDT 2001


7 MB is not so much that you couldn't read it all in on most systems.  Then
split on the byte sequence?

srcedata = open(filename).read()
fragments = srcedata.split(bytesequence)

eg:
>>> srcedata = "Thisthisisthisathistest"
>>> bytesequence="this"
>>> fragments = srcedata.split(bytesequence)
>>> fragments
['This', 'is', 'a', 'test']

HTH,

--

Emile van Sebille
emile at fenx.com

---------
"Rodney" <r.elliott at mech.canterbury.ac.nz> wrote in message
news:45956635.0110101132.245dcbf6 at posting.google.com...
> Hi Everyone,
>
> I started playing with python last night for the first time and I have
> run into a problem regarding data types.
>
> I have a large (7MB or so) file of raw hex data (ie values E{0,255})
> from which I need to identify a given byte sequence that occurs about
> 800 000 times within the file.  Once I have found these data fragments
> I need to extract them to another file.  My problem is that while I
> have been able to open the file and use read(10) etc to look at the
> file, I am unable to process it - I tried using input[23:67] (where
> 'input' is the name of the file I am working with) but python
> complained that I was using an unslicable type.
>
> So my question is how do I my file into a format where I am able to
> use RE's in python to play with it?  When I input.read(10) it looks
> like:
>
> x05\x0A\x45\xA1...
>
> That is raw hex data.  All suggestions most welcome.
>
>  - Rodney




More information about the Python-list mailing list