On Apr 2, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > how can i compare a string which is non null and empty? > > i look thru the string methods here, but cant find one which does it? > > http://docs.python.org/lib/string-methods.html#string-methods > > In java,I do this: > if (str != null) && (!str.equals("")) .... > > how can i do that in python? The closest to null in python is None. Do you initialise the string to have a value of None? eg myStr = None
if so, you can test with if myStr == None: dosomething... But you might find that you do not need to use None - just initialise the string as empty eg myStr = '' and then test for if myStr != '': or even simpler if myStr: dosomething btw. dont use 'str' - its a built in function of python -- http://mail.python.org/mailman/listinfo/python-list