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
  • 18,038
  • 6
  • 44
  • 52
Brad
  • 10,916
  • 8
  • 52
  • 70

0 Answers0