Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, traceback
- def force_load(broken_name):
- locals = dict()
- lines = []
- with open(broken_name + '.py', 'r') as file:
- for line in file:
- lines.append(line)
- SUCCESS = False
- while not SUCCESS:
- bad_line = 0
- SUCCESS = True
- try:
- exec(''.join(lines), globals(), locals)
- except SyntaxError as exs:
- bad_line = exs.lineno
- SUCCESS = False
- except Exception as exs:
- cl, exc, tb = sys.exc_info()
- bad_line = traceback.extract_tb(tb)[-1][1]
- SUCCESS = False
- if(not SUCCESS):
- del lines[bad_line-1]
- return locals
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement