コード例 #1
0
ファイル: zhpy.py プロジェクト: BGCX261/zhpy-svn-to-git
def try_run(result):
    """
    execute result and catch exceptions
    
Accept args:
    result:
        the converted source to be executed

    >>> try_run("print 'hello'")
    hello
    """
    try:
        locals = {"__name__": "__main__", "__doc__": None}
        # able to import modules in current directory
        sys.path.insert(0, '')
        exec result in locals
    except Exception, e:
        print result
        s = str(e)
        print s
        for k, v in worddict.items():
            if "'" + v + "'" in s:
                print unicode(k,"utf8"), v
            if '"' + v + '"' in s:
                print unicode(k,"utf8"), v
コード例 #2
0
def try_run(result):
    """
    execute result and catch exceptions
    
Accept args:
    result:
        the converted source to be executed

    >>> try_run("print 'hello'")
    hello
    """
    try:
        locals = {"__name__": "__main__", "__doc__": None}
        # able to import modules in current directory
        sys.path.insert(0, '')
        exec result in locals
    except Exception, e:
        print result
        s = str(e)
        print s
        for k, v in worddict.items():
            if "'" + v + "'" in s:
                print unicode(k,"utf8"), v
            if '"' + v + '"' in s:
                print unicode(k,"utf8"), v
コード例 #3
0
ファイル: zhpy.py プロジェクト: BGCX261/zhpy-svn-to-git
def try_run(result, global_ns={}, local_ns={}):
    """
    execute result and catch exceptions in specified namespace
    
Accept args:
    result:
        the converted source to be executed
    global_ns:
        Global namespace, deafult is {}
    local_ns:
        Local namespace, default is: {}

    >>> global_ns = {'x':'g'}
    >>> local_ns = {'x':'l'}
    >>> global_ns.update( {"__name__": "__main__", "__doc__": None})
    >>> try_run("print 'hello'", {}, {})
    hello
    >>> try_run("print x", global_ns, local_ns)
    l
    >>> try_run("print x", global_ns)
    g
    """
    try:
        # able to import modules in current directory
        sys.path.insert(0, '')
        exec result in global_ns, local_ns
    except Exception, e:
        print result
        s = str(e)
        print s
        for k, v in worddict.items():
            if "'" + v + "'" in s:
                print unicode(k, "utf8"), v
            if '"' + v + '"' in s:
                print unicode(k, "utf8"), v
コード例 #4
0
def try_run(result):
    """
    execute result and catch exceptions
    
    >>> try_run("print 'hello'")
    hello
    """
    try:
        locals = {"__name__": "__main__", "__doc__": None}
        exec result in locals
    except Exception, e:
        print result
        s = str(e)
        print s
        for k, v in worddict.items():
            if "'" + v + "'" in s:
                print unicode(k, "utf8"), v
            if '"' + v + '"' in s:
                print unicode(k, "utf8"), v
コード例 #5
0
ファイル: zhpy.py プロジェクト: BGCX261/zhpy-svn-to-git
def try_run(result):
    """
    execute result and catch exceptions
    
    >>> try_run("print 'hello'")
    hello
    """
    try:
        locals = {"__name__": "__main__", "__doc__": None}
        exec result in locals
    except Exception, e:
        print result
        s = str(e)
        print s
        for k, v in worddict.items():
            if "'" + v + "'" in s:
                print unicode(k,"utf8"), v
            if '"' + v + '"' in s:
                print unicode(k,"utf8"), v