string.digits, string.letters? How?

Terry Reedy tjreedy at home.com
Wed Oct 17 12:40:42 EDT 2001


"Paul Lim" <paullim at starhub.net.sg> wrote in message
news:3BCDCC6F.16954B08 at starhub.net.sg...
> Hi again to all,
>
> I am a newbie in Python and please really pardon me for my trivial
> question.
>
> How can we use the digits, letters variable in the string modules?
>
> I have the following snippet of my code
>
> # Import library modules
> # ======================
>
> import sys
> from string import lower, find, atoi, digits, letters
>
> if digits(sys.argv[i+1]):
>    print "Invalid argument"
>
> but i get the error message
>   File "test.py", line 32, in ?
>     if digits(sys.argv[i+1]):
> TypeError: object is not callable: '0123456789'
>
> What is wrong?
Try
print type(digits), digits, type(argv[i+1])
and see what you get.  Print (and type() are your debugging friends.
Then try
for char in sys.argv[i+i]:
  if char in digits: print "Bad"

Terry J. Reedy






More information about the Python-list mailing list