string % dictionary question

Bryan belred1 at yahoo.com
Tue Sep 14 06:47:56 CEST 2004


Sam Sungshik Kong wrote:
> Thanks for the reply.
> 
> What if the string is more complicated?
> For example,
> 
> di = {}
> di["name"] = "Sam"
> di["age"] = None
> s = "name: %(name)s, age: %(age)d" % di
> 
> Thanks.
> 
> Sam
> 

instead of setting di['age'] to None, set it to empty string.  if you are setting di['age'] with a variable then you can 
insure that you use an empty string for None by doing something like this:


di['age'] = somevar or ''



bryan



More information about the Python-list mailing list