好的,这里有一些简单的要点。PyBinding附带了这个脚本:
def IsNotNull(value):
return value is not None它很接近,但我想要的是这个。
bool IsNotNullOrEmpty(string value) {
return (value != null) && (value.Length > 0 );
}发布于 2010-01-25 09:41:27
要检查字符串是否为空,可以使用len。试试这个:
def IsNotNull(value):
return value is not None and len(value) > 0发布于 2010-01-25 09:48:20
您不应该在函数中执行此操作。相反,您应该只使用:
if someStringOrNone:发布于 2010-12-14 19:40:11
如果是IronPython,为什么不使用System.String的默认IsNullOrEmpty实现呢?
import clr
clr.AddReference('System')
import System
System.String.IsNullOrEmpty('') # returns True
System.String.IsNullOrEmpty(None) # returns True
System.String.IsNullOrEmpty('something') # returns Falsehttps://stackoverflow.com/questions/2129713
复制相似问题