- over.core.misc.console now accepts globals as well as locals to offer a complete environment
- new over.core.file.count_lines - over.core.types.ndict can now export keys with dashes in them same way over.core.app.Main does it (by translating them to underscores)
This commit is contained in:
parent
043ad86808
commit
402a05f86d
5 changed files with 32 additions and 4 deletions
14
core/misc.py
14
core/misc.py
|
@ -1,6 +1,7 @@
|
|||
#! /bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import copy
|
||||
import imp
|
||||
import os
|
||||
|
||||
|
@ -48,18 +49,25 @@ def batch_gen(data, batch_size):
|
|||
|
||||
# --------------------------------------------------
|
||||
|
||||
def console(environment, tab_completion=False):
|
||||
def console(locals, globals=None, tab_completion=False):
|
||||
'''
|
||||
Opens up a Python console.
|
||||
|
||||
environment is a dictionary typically returned by locals() or similar
|
||||
tab_completion enables completion of object names using TAB, however note
|
||||
that this will make pasting formatted snippets of code difficult
|
||||
'''
|
||||
|
||||
import code, readline, rlcompleter
|
||||
|
||||
readline.parse_and_bind('tab: complete')
|
||||
environment = copy.copy(locals)
|
||||
|
||||
if globals:
|
||||
for key, value in globals.items():
|
||||
if key not in environment:
|
||||
environment[key] = value
|
||||
|
||||
if tab_completion:
|
||||
readline.parse_and_bind('tab: complete')
|
||||
|
||||
c = code.InteractiveConsole(environment)
|
||||
c.interact(banner='')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue