[...]
> 
>   def myprint(num, places=4, *args, **kargs):
>       fmt_str = "{:." + str(places) + "f}"
>       print(fmt_str.format(num), *args, **kargs)

OK, quick update because I just realised how weird it is to have positional
arguments after a (potential) keyword argument (I really should go to bed).
Either of these is better:

  # "places" is exclusively a keyword argument now
  def myprint(num, *args, places=4, **kargs):
      fmt_str = "{:." + str(places) + "f}"
      print(fmt_str.format(num), *args, **kargs)

  # doesn't support extra arguments to print(), but is simpler
  def myprint(num, places=4):
      fmt_str = "{:." + str(places) + "f}"
      print(fmt_str.format(num))

-- 
Marc Joliet
--
"People who think they know everything really annoy those of us who know we
don't" - Bjarne Stroustrup

Attachment: signature.asc
Description: PGP signature

Reply via email to