我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用_thread.get_locals()。
def get_members_for_frame(self, expression, thread, cur_frame, frame_kind): """returns a tuple of the type name, instance members, and type members""" getattr_func = getattr if not expression: all_members = {} if sys.platform == 'cli': code = python_context.CreateSnippet('vars()', None, SourceCodeKind.AutoDetect) globals = code.Execute(Scope(cur_frame.f_globals)) locals = code.Execute(Scope(thread.get_locals(cur_frame, frame_kind))) else: globals = cur_frame.f_globals locals = thread.get_locals(cur_frame, frame_kind) for key, value in globals.items(): all_members[key] = self.get_type_name(value) for key, value in locals.items(): all_members[key] = self.get_type_name(value) return '', all_members, {} else: if sys.platform == 'cli': scope = Scope(cur_frame.f_globals) code = python_context.CreateSnippet(expression, None, SourceCodeKind.AutoDetect) val = code.Execute(scope) code = python_context.CreateSnippet('dir(' + expression + ')', None, SourceCodeKind.AutoDetect) members = code.Execute(scope) code = python_context.CreateSnippet('lambda value, name: getattr(value, name)', None, SourceCodeKind.AutoDetect) getattr_func = code.Execute(scope) else: val = eval(expression, cur_frame.f_globals, thread.get_locals(cur_frame, frame_kind)) members = dir(val) return self.collect_members(val, members, getattr_func)
def get_signatures_for_frame(self, expression, thread, cur_frame, frame_kind): if sys.platform == 'cli': code = python_context.CreateSnippet(expression, None, SourceCodeKind.AutoDetect) val = code.Execute(Scope(cur_frame.f_globals)) else: val = eval(expression, cur_frame.f_globals, thread.get_locals(cur_frame, frame_kind)) return self.collect_signatures(val)