Python __main__.__dict__() Examples
The following are 30
code examples of __main__.__dict__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
__main__
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: rlcompleter.py From meddle with MIT License | 7 votes |
def complete(self, text, state): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. """ if self.use_main_ns: self.namespace = __main__.__dict__ if state == 0: if "." in text: self.matches = self.attr_matches(text) else: self.matches = self.global_matches(text) try: return self.matches[state] except IndexError: return None
Example #2
Source File: rlcompleter.py From meddle with MIT License | 7 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #3
Source File: rlcompleter.py From ironpython2 with Apache License 2.0 | 7 votes |
def complete(self, text, state): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. """ if self.use_main_ns: self.namespace = __main__.__dict__ if state == 0: if "." in text: self.matches = self.attr_matches(text) else: self.matches = self.global_matches(text) try: return self.matches[state] except IndexError: return None
Example #4
Source File: bdb.py From oss-ftp with MIT License | 6 votes |
def run(self, cmd, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(cmd, types.CodeType): cmd = cmd+'\n' try: exec cmd in globals, locals except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #5
Source File: rlcompleter.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def complete(self, text, state): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. """ if self.use_main_ns: self.namespace = __main__.__dict__ if not text.strip(): if state == 0: return '\t' else: return None if state == 0: if "." in text: self.matches = self.attr_matches(text) else: self.matches = self.global_matches(text) try: return self.matches[state] except IndexError: return None
Example #6
Source File: bdb.py From BinderFilter with MIT License | 6 votes |
def runeval(self, expr, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(expr, types.CodeType): expr = expr+'\n' try: return eval(expr, globals, locals) except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #7
Source File: completer.py From Computable with MIT License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace or self.global_namespace that match. """ #print 'Completer->global_matches, txt=%r' % text # dbg matches = [] match_append = matches.append n = len(text) for lst in [keyword.kwlist, __builtin__.__dict__.keys(), self.namespace.keys(), self.global_namespace.keys()]: for word in lst: if word[:n] == text and word != "__builtins__": match_append(word) return matches
Example #8
Source File: debugger.py From ironpython2 with Apache License 2.0 | 6 votes |
def RespondDebuggerState(self, state): globs = locs = None if state==DBGSTATE_BREAK: if self.debugger.curframe: globs = self.debugger.curframe.f_globals locs = self.debugger.curframe.f_locals elif state==DBGSTATE_NOT_DEBUGGING: import __main__ globs = locs = __main__.__dict__ for i in range(self.GetItemCount()-1): text = self.GetItemText(i, 0) if globs is None: val = "" else: try: val = repr( eval( text, globs, locs) ) except SyntaxError: val = "Syntax Error" except: t, v, tb = sys.exc_info() val = traceback.format_exception_only(t, v)[0].strip() tb = None # prevent a cycle. self.SetItemText(i, 1, val)
Example #9
Source File: bdb.py From meddle with MIT License | 6 votes |
def runeval(self, expr, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(expr, types.CodeType): expr = expr+'\n' try: return eval(expr, globals, locals) except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #10
Source File: bdb.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def run(self, cmd, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() if isinstance(cmd, str): cmd = compile(cmd, "<string>", "exec") sys.settrace(self.trace_dispatch) try: exec(cmd, globals, locals) except BdbQuit: pass finally: self.quitting = True sys.settrace(None)
Example #11
Source File: intpyapp.py From ironpython2 with Apache License 2.0 | 6 votes |
def OnViewBrowse( self, id, code ): " Called when ViewBrowse message is received " from pywin.mfc import dialog from pywin.tools import browser obName = dialog.GetSimpleInput('Object', '__builtins__', 'Browse Python Object') if obName is None: return try: browser.Browse(eval(obName, __main__.__dict__, __main__.__dict__)) except NameError: win32ui.MessageBox('This is no object with this name') except AttributeError: win32ui.MessageBox('The object has no attribute of that name') except: traceback.print_exc() win32ui.MessageBox('This object can not be browsed')
Example #12
Source File: completer.py From Computable with MIT License | 6 votes |
def complete(self, text, state): """Return the next possible completion for 'text'. This is called successively with state == 0, 1, 2, ... until it returns None. The completion should begin with 'text'. """ if self.use_main_ns: self.namespace = __main__.__dict__ if state == 0: if "." in text: self.matches = self.attr_matches(text) else: self.matches = self.global_matches(text) try: return self.matches[state] except IndexError: return None
Example #13
Source File: rlcompleter.py From BinderFilter with MIT License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #14
Source File: bdb.py From BinderFilter with MIT License | 6 votes |
def run(self, cmd, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(cmd, types.CodeType): cmd = cmd+'\n' try: exec cmd in globals, locals except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #15
Source File: ROOT.py From parliament2 with Apache License 2.0 | 6 votes |
def __setattr2( self, name, value ): # "running" getattr # to allow assignments to ROOT globals such as ROOT.gDebug if not name in self.__dict__: try: # assignment to an existing ROOT global (establishes proxy) setattr( self.__class__, name, _root.GetCppGlobal( name ) ) except LookupError: # allow a few limited cases where new globals can be set if sys.hexversion >= 0x3000000: pylong = int else: pylong = long tcnv = { bool : 'bool %s = %d;', int : 'int %s = %d;', pylong : 'long %s = %d;', float : 'double %s = %f;', str : 'string %s = "%s";' } try: _root.gROOT.ProcessLine( tcnv[ type(value) ] % (name,value) ); setattr( self.__class__, name, _root.GetCppGlobal( name ) ) except KeyError: pass # can still assign normally, to the module # actual assignment through descriptor, or normal python way return super( self.__class__, self ).__setattr__( name, value )
Example #16
Source File: rlcompleter.py From ironpython2 with Apache License 2.0 | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, __builtin__.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #17
Source File: bdb.py From ironpython2 with Apache License 2.0 | 6 votes |
def run(self, cmd, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(cmd, types.CodeType): cmd = cmd+'\n' try: exec cmd in globals, locals except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #18
Source File: bdb.py From ironpython2 with Apache License 2.0 | 6 votes |
def runeval(self, expr, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(expr, types.CodeType): expr = expr+'\n' try: return eval(expr, globals, locals) except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #19
Source File: pydev_umd.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
def _get_globals(): """Return current Python interpreter globals namespace""" if _get_globals_callback is not None: return _get_globals_callback() else: try: from __main__ import __dict__ as namespace except ImportError: try: # The import fails on IronPython import __main__ namespace = __main__.__dict__ except: namespace shell = namespace.get('__ipythonshell__') if shell is not None and hasattr(shell, 'user_ns'): # IPython 0.12+ kernel return shell.user_ns else: # Python interpreter return namespace return namespace
Example #20
Source File: rlcompleter.py From oss-ftp with MIT License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] n = len(text) for word in keyword.kwlist: if word[:n] == text: matches.append(word) for nspace in [__builtin__.__dict__, self.namespace]: for word, val in nspace.items(): if word[:n] == text and word != "__builtins__": matches.append(self._callable_postfix(val, word)) return matches
Example #21
Source File: rlcompleter.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ import keyword matches = [] seen = {"__builtins__"} n = len(text) for word in keyword.kwlist: if word[:n] == text: seen.add(word) matches.append(word) for nspace in [self.namespace, builtins.__dict__]: for word, val in nspace.items(): if word[:n] == text and word not in seen: seen.add(word) matches.append(self._callable_postfix(val, word)) return matches
Example #22
Source File: bdb.py From oss-ftp with MIT License | 6 votes |
def runeval(self, expr, globals=None, locals=None): if globals is None: import __main__ globals = __main__.__dict__ if locals is None: locals = globals self.reset() sys.settrace(self.trace_dispatch) if not isinstance(expr, types.CodeType): expr = expr+'\n' try: return eval(expr, globals, locals) except BdbQuit: pass finally: self.quitting = 1 sys.settrace(None)
Example #23
Source File: cProfile.py From oss-ftp with MIT License | 5 votes |
def run(self, cmd): import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict)
Example #24
Source File: cProfile.py From Computable with MIT License | 5 votes |
def run(self, cmd): import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict)
Example #25
Source File: trace.py From oss-ftp with MIT License | 5 votes |
def run(self, cmd): import __main__ dict = __main__.__dict__ self.runctx(cmd, dict, dict)
Example #26
Source File: ROOT.py From parliament2 with Apache License 2.0 | 5 votes |
def __init__( self, module ): types.ModuleType.__init__( self, 'ROOT' ) self.__dict__[ 'module' ] = module self.__dict__[ '__doc__' ] = self.module.__doc__ self.__dict__[ '__name__' ] = self.module.__name__ self.__dict__[ '__file__' ] = self.module.__file__ self.__dict__[ 'keeppolling' ] = 0 self.__dict__[ 'PyConfig' ] = self.module.PyConfig class gROOTWrapper( object ): def __init__( self, gROOT, master ): self.__dict__[ '_master' ] = master self.__dict__[ '_gROOT' ] = gROOT def __getattr__( self, name ): if name != 'SetBatch' and self._master.__dict__[ 'gROOT' ] != self._gROOT: self._master._ModuleFacade__finalSetup() del self._master.__class__._ModuleFacade__finalSetup return getattr( self._gROOT, name ) def __setattr__( self, name, value ): return setattr( self._gROOT, name, value ) self.__dict__[ 'gROOT' ] = gROOTWrapper( _root.gROOT, self ) del gROOTWrapper # begin with startup gettattr/setattr self.__class__.__getattr__ = self.__class__.__getattr1 del self.__class__.__getattr1 self.__class__.__setattr__ = self.__class__.__setattr1 del self.__class__.__setattr1
Example #27
Source File: profile.py From oss-ftp with MIT License | 5 votes |
def run(self, cmd): import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict)
Example #28
Source File: rlcompleter.py From oss-ftp with MIT License | 5 votes |
def __init__(self, namespace = None): """Create a new completer for the command line. Completer([namespace]) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictionaries. Completer instances should be used as the completion mechanism of readline via the set_completer() call: readline.set_completer(Completer(my_namespace).complete) """ if namespace and not isinstance(namespace, dict): raise TypeError,'namespace must be a dictionary' # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us # to bind to __main__.__dict__ at completion time, not now. if namespace is None: self.use_main_ns = 1 else: self.use_main_ns = 0 self.namespace = namespace
Example #29
Source File: completer.py From Computable with MIT License | 5 votes |
def __init__(self, namespace=None, global_namespace=None, **kwargs): """Create a new completer for the command line. Completer(namespace=ns,global_namespace=ns2) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictionaries. An optional second namespace can be given. This allows the completer to handle cases where both the local and global scopes need to be distinguished. Completer instances should be used as the completion mechanism of readline via the set_completer() call: readline.set_completer(Completer(my_namespace).complete) """ # Don't bind to namespace quite yet, but flag whether the user wants a # specific namespace or to use __main__.__dict__. This will allow us # to bind to __main__.__dict__ at completion time, not now. if namespace is None: self.use_main_ns = 1 else: self.use_main_ns = 0 self.namespace = namespace # The global namespace, if given, can be bound directly if global_namespace is None: self.global_namespace = {} else: self.global_namespace = global_namespace super(Completer, self).__init__(**kwargs)
Example #30
Source File: __init__.py From oss-ftp with MIT License | 5 votes |
def run(self, cmd): """Profile an exec-compatible string in the script environment. The globals from the __main__ module are used as both the globals and locals for the script. """ import __main__ dict = __main__.__dict__ return self.runctx(cmd, dict, dict)