Steven Howe a écrit :
(nb : original post reinserted)
> [EMAIL PROTECTED] a écrit :
>> how can i compare a string which is non null and empty?
>>
(snip)
>> In java,I do this:
>> if (str != null) && (!str.equals(""))
>>
>> how can i do that in python?
>
> how about just testing it's length?
On Mon, 02 Apr 2007 13:48:30 -0700, Steven Howe wrote:
> how about just testing it's length?
> >>> from types import StringType
>
> def stringTest(x):
> ... if type(x) == StringType:
> ... if len(x) == 0:
> ... print 'Empty String'
> ... else:
> ..
how about just testing it's length?
>>> from types import StringType
def stringTest(x):
... if type(x) == StringType:
... if len(x) == 0:
... print 'Empty String'
... else:
... print 'Not Empty String'
... else:
...
[EMAIL PROTECTED] a écrit :
> Hi,
>
> how can i compare a string which is non null and empty?
Compare with what ?-)
>
> 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 != n
On Mon, 02 Apr 2007 01:35:17 +0200, Georg Brandl wrote:
> [EMAIL PROTECTED] schrieb:
>> 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-m
On 2007-04-02, Shane Geiger <[EMAIL PROTECTED]> wrote:
>>> how can i compare a string which is non null and empty?
>>>
>> [...]
>>
>>> In java,I do this:
>>> if (str != null) && (!str.equals(""))
>>>
>>> how can i do that in python?
>>
>> If you want to litterally do that, it's
>>
>>
It is probably worth noting that the example is not executable code:
str() is a function.
[EMAIL PROTECTED]:~$ python
Python 2.4.4c0 (#2, Jul 30 2006, 15:43:58)
[GCC 4.1.2 20060715 (prerelease) (Debian 4.1.1-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>
On 2007-04-01, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> how can i compare a string which is non null and empty?
[...]
> In java,I do this:
> if (str != null) && (!str.equals(""))
>
> how can i do that in python?
If you want to litterally do that, it's
if (str != None) and (str != ""
str != ""
returns true if str is NOT the empty string.
str is not None
returns true if str is null (or None as it's called in python).
To check to make sure a string is nonnull and nonempty, do:
str is not None and str != ""
--
http://mail.python.org/mailman/listinfo/python-list
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:
> i
[EMAIL PROTECTED] schrieb:
> 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("
[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
12 matches
Mail list logo