string % dictionary question

Larry Bates lbates at swamisoft.com
Tue Sep 14 10:27:30 EDT 2004


di={}
di["test"]=None
s="%s" % (di["test"] or "")
print "s='%s'" % s

works, but might be better to set values to empty strings
unless you want to test for the existence of None somewhere
else in your program.

Larry Bates

"Sam Sungshik Kong" <ssk at chol.nospam.net> wrote in message
news:ZFq1d.15197$QJ3.11816 at newssvr21.news.prodigy.com...
> Hello, group!
>
> <code>
> >>> di={}
> >>> di["test"]=None
> >>> s="%(test)s" % di
> >>> s
> 'None'
> </code>
>
> I want the result to be just empty string when the dictionary value is
None.
> Is there a good way?
>
> TIA.
> Sam
>
>





More information about the Python-list mailing list