<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 2012/01/31 06:50 AM, Michael Lewis wrote:
    <blockquote
cite="mid:CAE5MWfXZ9Jkm8-ATYxTenNnfjc4SUx4LomwW+gCrTOX6oOHaPA@mail.gmail.com"
      type="cite">
      <div dir="ltr">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?
        <div>
          <br>
        </div>
        <div>
          <div>def TestY(y):</div>
          <div>    try:</div>
          <div>        y = int(y)</div>
          <div>    except ValueError:</div>
          <div>        pass</div>
          <div>    if y &lt; -1 or y &gt; 1:</div>
          <div>        value = 82</div>
          <div>        print value</div>
          <div>    else:</div>
          <div>        pass</div>
          <div><br>
          </div>
          -- <br>
          <div dir="ltr">
            <div>Michael J. Lewis</div>
            <div> </div>
            <div><a moz-do-not-send="true"
                href="mailto:mjolewis@gmail.com" target="_blank">mjolewis@gmail.com</a>
            </div>
            <div>415.815.7257</div>
          </div>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Tutor maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a>
To unsubscribe or change subscription options:
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a></pre>
    </blockquote>
    If you just want to test if `y` is an integer you can do so with
    `type(y) == int`, and to get the ASCII value of a character you can
    use `ord` like `ord('a') == 97`. And how to avoid your ValueError
    with a bad conversion, do your type checking before hand.<br>
    <br>
    Hope that helps.<br>
    <div class="moz-signature">-- <br>
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <title>Email Signature</title>
      <style type="text/css">
p { font-size:8.5pt; font-family: Arial, Helvetica, sans-serif; color: #000;}
.subscribe {font-weight:bold; font-style:italic;}
.compuscan {color: #c60c30; letter-spacing:2px; text-transform:uppercase; font-weight:bold}
.green {color:#093;}
</style>
      <p>Christian Witts<br>
        Python Developer<br>
        <em class="green"></em></p>
    </div>
  </body>
</html>