SHARE
TWEET

SyntaxCheck - Function

nux95 Jun 3rd, 2011 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from sys import exc_info
  2. def SyntaxCheck(code):
  3.     lines            = code.count("\n") + 1
  4.  
  5.     code            += "\nI'm a Syntax Error !"
  6.     lineWithError    = lines + 1
  7.  
  8.     try:
  9.         exec code in {}, {}
  10.     except SyntaxError:
  11.         error        = exc_info()[1]
  12.         line         = error.lineno
  13.         column       = error.offset
  14.         text         = error.text
  15.  
  16.         if line == lineWithError:
  17.             return
  18.         else:
  19.             return line, column, text
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top