Jason wrote:
> I believe what you are trying to do is something like the following.
> 
> [code]
> def isIntLike(x):
>       try:    int(x)
>       except: return False

*Never* ever use a bare except clause. *Always* specify wich exceptions
you are expecting. (NB : here, TypeError and ValueError).

(NB :  of course, like for all and any do's-and-don't rules, there are
actually a very few cases where using a bare except may be ok.)

>       else:   return True
> 
> something = raw_input("Enter something and I will tell you the type: ")
> 
> if isIntLike(something):      print "I am an int"

Nope. At this stage, 'something' is *not* an int - it's a string that
can be turned into an int.

> elif isinstance(something, type('')): print "I am a string"

You don't need the "type('')" stuff - use isinstance(something,
basestring) instead.

> else: print "I am an impostor!"
> [/code]

(snip)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to