Advertisement
d_skat

Untitled

Apr 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import sys, traceback
  2.  
  3.  
  4. def force_load(broken_name):
  5.     locals = dict()
  6.     lines = []
  7.     with open(broken_name + '.py', 'r') as file:
  8.         for line in file:
  9.             lines.append(line)
  10.     SUCCESS = False
  11.     while not SUCCESS:
  12.         bad_line = 0
  13.         SUCCESS = True
  14.         try:
  15.             exec(''.join(lines), globals(), locals)
  16.         except SyntaxError as exs:
  17.             bad_line = exs.lineno
  18.             SUCCESS = False
  19.         except Exception as exs:
  20.             cl, exc, tb = sys.exc_info()
  21.             bad_line = traceback.extract_tb(tb)[-1][1]
  22.             SUCCESS = False
  23.         if(not SUCCESS):
  24.             del lines[bad_line-1]
  25.     return locals
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement