[Tutor] Request for guidance about a python syntax

Jerry Hill malaclypse2 at gmail.com
Mon Dec 19 17:15:13 CET 2011


On Mon, Dec 19, 2011 at 10:54 AM, Ganesh Borse <bganesh05 at gmail.com> wrote:

> I could know the use of unpack_from, but I could not understand the "fmt"
> part, i.e *"%dH" % nframes * nchannels*.
> Can you pls help me know, what is the purpose of two "%" signs in this
> statement?
>
>
That's python's string formatting.  See
http://docs.python.org/library/stdtypes.html#string-formatting-operations for
details.  Basically, it's building the format for the call to unpack_from
on the fly.  The "%dH" portion is calling for a single decimal value to
become part of the string (that's the "%d" portion).  That value comes from
multiplying nframes by nchannels.  So, for example, if nframes = 10 and
nchannels = 24, then the string becomes "240H".  That, in turn, tells the
program to unpack a sequence of 240 unsigned short values from the buffer.

-- 
Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111219/6a16e565/attachment.html>


More information about the Tutor mailing list