How to check if a string is empty in python?

Alex Martelli aleax at mac.com
Thu May 3 00:59:56 EDT 2007


mensanator at aol.com <mensanator at aol.com> wrote:
   ...
> >>> import gmpy
> >>> gmpy.mpz(11)
> mpz(11)
> >>> gmpy.mpz('11',10)
> mpz(11)
> >>> gmpy.mpz(11,10)
> 
> Traceback (most recent call last):
>   File "<pyshell#38>", line 1, in <module>
>     gmpy.mpz(11,10)
> TypeError: gmpy.mpz() with numeric argument needs exactly 1 argument
> 
> The mpz conversion takes two arguments if and only if s is a string,
> else it takes 1 argument. So being non-empty is insufficient.

Being a string AND being non-empty is insufficient too -- just try

gmpy.mpz("Hello, I am a string and definitely not empy!", 10)

on for size.


Alex



More information about the Python-list mailing list