On 11/01/06, bill nieuwendorp <[EMAIL PROTECTED]> wrote:

Hi Bill,

Some comments ---

> >>> import struct
> >>> import string
> >>> f = file('binary_file','rb')
> >>> line = f.readline()
> >>> L = tuple(line)

You can do slicing (things like L[:4]) on strings as well as on lists
and tuples.  So there is probably no need for you to convert to a
tuple --- just work with the lines directly.

> >>> s = L[:4]
> >>> s
> ('\x00', '\x00', '\x00', '\x06')
> >>> a = string.join( s , '')

You can also do:

   a = ''.join(s)

and this is considered better python these days.

> what I need is a way to do somthing like this
>
> time = struct.unpack(">steps",c)
>
> but this does not work because steps is not an integer

Sounds like you want string substitutions..  You can read about them
here: http://python.org/doc/2.4.2/lib/typesseq-strings.html

For instance:

>>> steps = 6
>>> ">%s" % steps
'>6'

HTH!

--
John.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to