How to replace all None values with the string "Null" in a dictionary

Steve Holden steve at holdenweb.com
Thu Oct 27 16:44:35 EDT 2005


dcrespo wrote:
> Hi all,
> 
> How can I replace all None values with the string 'Null' in a
> dictionary?
> 
> For example:
> convert this:
> a = {'item1': 45, 'item2': None}
> 
> into this:
> a = {'item1': 45, 'item2': 'Null'}
> 
for k in a:
   if a[k] is None:
     a[k] = 'Null'

You aren't doing this to create SQL statements, are you? If so, 
parameterized queries are the way to go ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list