Questions tagged «nonetype»

11
如果字典键不可用,则返回None
我需要一种方法来获取字典值(如果它的键存在),或者简单地返回None,如果它不存在。 但是,KeyError如果您搜索不存在的键,Python会引发异常。我知道我可以检查密钥,但是我正在寻找更明确的密钥。None如果密钥不存在,是否有办法返回?

7
如何在Python中“测试” NoneType?
我有一个有时返回NoneType值的方法。那么我如何质疑一个无类型的变量呢?例如,我需要使用if方法 if not new: new = '#' 我知道这是错误的方式,希望您能理解我的意思。
398 python  nonetype 


9
从列表中删除无值而不删除0值
这是我开始的来源。 我的清单 L = [0, 23, 234, 89, None, 0, 35, 9] 当我运行这个: L = filter(None, L) 我得到这个结果 [23, 234, 89, 35, 9] 但这不是我所需要的,我真正需要的是: [0, 23, 234, 89, 0, 35, 9] 因为我正在计算数据的百分位数,所以0会产生很大的不同。 如何从列表中删除无值而不删除0值?
244 python  list  filter  nonetype 


7
TypeError:“ NoneType”对象在Python中不可迭代
错误TypeError: 'NoneType' object is not iterable是什么意思? 我在以下Python代码上得到它: def write_file(data, filename): # creates file and writes list to it with open(filename, 'wb') as outfile: writer = csv.writer(outfile) for row in data: # ABOVE ERROR IS THROWN HERE writer.writerow(row)
145 python  nonetype 

5
在熊猫数据框中将NaN替换为None
我有桌子x: website 0 http://www.google.com/ 1 http://www.yahoo.com 2 None 我想用NaN替换python None。我试过了: x.replace(to_replace=None, value=np.nan) 但是我得到了: TypeError: 'regex' must be a string or a compiled regular expression or a list or dict of strings or regular expressions, you passed a 'bool' 我应该怎么做?

9
什么是“ NoneType”对象?
运行python脚本时出现此错误: TypeError: cannot concatenate 'str' and 'NoneType' objects 我很确定'str'是字符串,但是我不知道'NoneType'对象是什么。我的脚本在第二行开始,我知道第一个行之有效,因为该行的命令符合我的期望。起初我以为可能是因为我在send_command中使用了变量和用户输入。 “ CAPS”中的所有内容都是变量,“小写”中的所有内容都是从“ parser.add_option”选项输入的。 我正在使用pexpect和optparse send_command(child, SNMPGROUPCMD + group + V3PRIVCMD) send_command(child, SNMPSRVUSRCMD + snmpuser + group + V3AUTHCMD + snmphmac + snmpauth + PRIVCMD + snmpencrypt + snmppriv)
87 python  null  nonetype 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.