[Tutor] need help with syntax
john at fouhy.net
Wed Jan 11 04:52:46 CET 2006
On 11/01/06, bill nieuwendorp <slow67 at gmail.com> wrote:
> time = struct.unpack(">steps+f",c)
> adding the f to tell structs it is in float format
> the string substitution
> seems like it would work but now I cant figure out how I would add the
> f on the end
Did you read up on string substitution? You can do a few tricks with
it, but in its simplest form, it just replaces '%s' with the argument.
'foo%sbar' % 'seven' == 'foosevenbar'
'x%sy%sz' % ('foo', 'bar') == 'xfooybarz'
So, in your case, try something like '>%s+f'.
> also this still requires me to reassign 6 to steps
> isnt this already done here ?
> >>> s = L[:4]
> >>> s
> ('\x00', '\x00', '\x00', '\x06')
> >>> a = string.join( s , '')
> >>> steps = struct.unpack (">l" , a)
> >>> steps
Yes, although in this case steps is a 1-element tuple. So, steps
will give you what you want :-)
More information about the Tutor