(expr, **settings)
return result
Return Python interpretation of passed expression
    (can be passed to the exec() function without any modifications)
Return Python interpretation of passed expression
    (can be passed to the exec() function without any modifications)
Return Python interpretation of passed expression ( can be passed to the exec () function without any modifications )
def python(expr, **settings):
    """Return Python interpretation of passed expression
    (can be passed to the exec() function without any modifications)"""

    printer = PythonPrinter(settings)
    exprp = printer.doprint(expr)

    result = ''
    # Returning found symbols and functions
    renamings = {}
    for symbolname in printer.symbols:
        newsymbolname = symbolname
        # Escape symbol names that are reserved python keywords
        if kw.iskeyword(newsymbolname):
            while True:
                newsymbolname += "_"
                if (newsymbolname not in printer.symbols and
                        newsymbolname not in printer.functions):
                    renamings[sympy.Symbol(
                        symbolname)] = sympy.Symbol(newsymbolname)
                    break
        result += newsymbolname + ' = Symbol(\'' + symbolname + '\')\n'

    for functionname in printer.functions:
        newfunctionname = functionname
        # Escape function names that are reserved python keywords
        if kw.iskeyword(newfunctionname):
            while True:
                newfunctionname += "_"
                if (newfunctionname not in printer.symbols and
                        newfunctionname not in printer.functions):
                    renamings[sympy.Function(
                        functionname)] = sympy.Function(newfunctionname)
                    break
        result += newfunctionname + ' = Function(\'' + functionname + '\')\n'

    if not len(renamings) == 0:
        exprp = expr.subs(renamings)
    result += 'e = ' + printer._str(exprp)
    return result
def python ( expr , * * settings ) : printer = PythonPrinter ( settings ) exprp = printer . doprint ( expr ) result = '' # Returning found symbols and functions renamings = { } for symbolname in printer . symbols : newsymbolname = symbolname # Escape symbol names that are reserved python keywords if kw . iskeyword ( newsymbolname ) : while True : newsymbolname += "_" if ( newsymbolname not in printer . symbols and newsymbolname not in printer . functions ) : renamings [ sympy . Symbol ( symbolname ) ] = sympy . Symbol ( newsymbolname ) break result += newsymbolname + ' = Symbol(\'' + symbolname + '\')\n' for functionname in printer . functions : newfunctionname = functionname # Escape function names that are reserved python keywords if kw . iskeyword ( newfunctionname ) : while True : newfunctionname += "_" if ( newfunctionname not in printer . symbols and newfunctionname not in printer . functions ) : renamings [ sympy . Function ( functionname ) ] = sympy . Function ( newfunctionname ) break result += newfunctionname + ' = Function(\'' + functionname + '\')\n' if not len ( renamings ) == 0 : exprp = expr . subs ( renamings ) result += 'e = ' + printer . _str ( exprp ) return result