1

I'm trying to do this in Python:

print "Test {one} Hello {another} Third {something}".format(**args)

Where "args" is a dict.

Is there anyway that I can use this function while not throwing an Exception if one (or more) of the keywords (in the string above) doesn't exist in "args"?

I can't just catch the exception, because I want the rest of the string to print. A "blank" or anything is fine for non-existent keywords.

Anyone know of any clever ways of dealing with this in-general? I run into it a lot and typically build a separate dict which is "safe-checked" against missing (or in my case optional data).

Amit
  • 19,780
  • 6
  • 46
  • 54
Brad
  • 11,262
  • 8
  • 55
  • 74

0 Answers0