string % dictionary question

Jorge Godoy godoy at ieee.org
Mon Sep 13 23:30:01 EDT 2004


"Sam Sungshik Kong" <ssk at chol.nospam.net> writes:

> 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?

You can check it after the definition and make the necessary changes... 

>>> di={}
>>> di["test"]=None
>>> s="%(test)s" % di
>>> if s == "None": s = ""
...
>>> s
''
>>> di["test"] = 1
>>> s = "%(test)s" % di
>>> if s == "None": s = ""
...
>>> s
'1'
>>>


Be seeing you,
-- 
Godoy.     <godoy at ieee.org>



More information about the Python-list mailing list