Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String is null or empty

Tags:

ironpython

Ok, here are some easy points. PyBinding came with this script:

def IsNotNull(value):
    return value is not None

It is close, but what I want is this.

bool IsNotNullOrEmpty(string value) {
    return (value != null) && (value.Length > 0 );
}
like image 609
Jonathan Allen Avatar asked Jan 25 '10 01:01

Jonathan Allen


2 Answers

To check if a string is empty you would use len. Try this:

def IsNotNull(value):
    return value is not None and len(value) > 0
like image 153
Brian McKenna Avatar answered Oct 18 '22 16:10

Brian McKenna


You should not be doing this in a function. Instead you should just use:

if someStringOrNone:
like image 36
Ignacio Vazquez-Abrams Avatar answered Oct 18 '22 17:10

Ignacio Vazquez-Abrams