[Tutor] ASCII Conversion

Michael Lewis mjolewis at gmail.com
Tue Jan 31 05:50:42 CET 2012

I am trying to do a simple test but am not sure how to get around ASCII
conversion of characters. I want to pass in y have the function test to see
if y is an integer and print out a value if that integer satisfies the if
statement. However, if I pass in a string, it's converted to ASCII and will
still satisfy the if statement and print out value. How do I ensure that a
string is caught as a ValueError instead of being converted?

def TestY(y):
        y = int(y)
    except ValueError:
    if y < -1 or y > 1:
        value = 82
        print value

Michael J. Lewis

mjolewis at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120130/2578531d/attachment.html>

More information about the Tutor mailing list