1

In the sec2time() Python function provided by Lee he uses a syntax I'm struggling to understand:

pattern = '%%02d:%%02d:%%0%d.%df' % (n_msec+3, n_msec)

What is the %%here and how does it affect the outcome?

Anthon
  • 69,918
  • 32
  • 186
  • 246

1 Answers1

0

The % in that string introduces replaceable parts as at the end %d.%df. If you want a % in the output you have to do something special, in this case use %%

After these substitustions the resulting pattern will look like:

'%02d:%02d:%0123.120f'

which, among other things an be used for further substitution.

In the documentation, at the bottem of the second table in that section, it states:

'%'        No argument is converted, results in a '%' character in the result.
Anthon
  • 69,918
  • 32
  • 186
  • 246