如何用字符串“Null”替换所有None值在字典中 [英] How to replace all None values with the string "Null" in a dictionary
问题描述
大家好,
如何在
字典中用字符串''Null'替换所有None值?
例如:
将此转换为:
a = {''item1'':45,''item2'':无}
到此:
a = {''item1'':45,''item2'':''Null''}
谢谢
Daniel
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''}
Thanks
Daniel
推荐答案
丹尼尔>如何在
Daniel>中用字符串''Null'替换所有None值。字典?
a = {''item1'':45,''item2'':无}
用于键入:
如果[key]为None:
a [key] =" Null"
Skip
Daniel> How can I replace all None values with the string ''Null'' in a
Daniel> dictionary?
a = {''item1'': 45, ''item2'': None}
for key in a:
if a[key] is None:
a[key] = "Null"
Skip
dcrespo写道:
dcrespo wrote:
大家好,
如何在
字典中用字符串''Null'替换所有None值?
例如:
将此转换为:
a = {''item1'':45,''item2'':无}
进入这个:
a = {''item1'':45,''item2'':''Null''}
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:
如果[k]为无:
a [k] =''Null''
你不是这样做的SQL语句,是吗?如果是这样的话,
参数化查询就可以了...
问候
Steve
-
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
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/
" dcrespo" <直流***** @ gmail.com>写道:
"dcrespo" <dc*****@gmail.com> writes:
大家好,
如何用
字典中的字符串''Null'替换所有None值?
Hi all,
How can I replace all None values with the string ''Null'' in a
dictionary?
迭代字典中的所有内容:
for key,mydict.items()中的项目:
如果项目为无:
mydict [key] =''Null''
< mike
-
Mike Meyer< mw*@mired.org> http://www.mired.org/home/mwm/
独立的WWW / Perforce / FreeBSD / Unix顾问,电子邮件以获取更多信息。
Iterate over everything in the dictionary:
for key, item in mydict.items():
if item is None:
mydict[key] = ''Null''
<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
这篇关于如何用字符串“Null”替换所有None值在字典中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!