当前位置: 首页>>代码示例>>Python>>正文


Python Context.evaluate方法代码示例

本文整理汇总了Python中context.Context.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Python Context.evaluate方法的具体用法?Python Context.evaluate怎么用?Python Context.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context.Context的用法示例。


在下文中一共展示了Context.evaluate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Context

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import evaluate [as 别名]
if __name__ == '__main__':
    from context import Context

    from binding import OMBinding, lambdasym

    context = Context()

    context.push({})

    context["x"] = OMint(1)

    x = OMVar("x")

    y = OMVar("y")

    print context.evaluate(x)
    print context.evaluate(y)
    firstArg=OMBinding(lambdasym,[OMVar("x"), OMVar("y")], OMVar("x"))
    #print context.evaluate(firstArg)
    application = OMApply(firstArg, [x,y])
    print context.evaluate(application)
    application = OMApply(firstArg, [y,x])
    print context.evaluate(application)
    import CD.arith1 as arith1
    context.addCDImplementation(arith1.implementation)
    #print type(context.lookupImplementation(arith1.plussym))
    #application=OMApply(arith1.plussym,[x])
    #application=OMApply(arith1.plussym,[x,x])
    application = OMApply(OMSymbol("plus", arith1.content), [x, x])
    
    print context.evaluate(application)
开发者ID:Macaulay2,项目名称:Singular,代码行数:33,代码来源:objects.py

示例2:

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import evaluate [as 别名]
import lxmlencoder
import lxmldecoder
import lxml.etree as et
import sys
from cd.arith1 import implementation as arith1
from context import Context

tree=et.parse("bindingbsp")
inp= lxmldecoder.decode(tree)
h=lxmlencoder.encode(inp)
print h.__class__
h.write(open("hallo", "w"))
c=Context()
c.addCDImplementation(arith1)
lxmlencoder.encode(c.evaluate(inp)).write(open("hallo.eval", "w"))
开发者ID:Macaulay2,项目名称:Singular,代码行数:17,代码来源:test_read.py

示例3: Repl

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import evaluate [as 别名]
class Repl(object):
    def __init__(self):
        self.history = FileHistory(history_file)
        self.context = Context({
            u'help': self.help,
            u'exit': self.exit,
            u'save': self.save,
            u'load': self.load_default,
        })

    @staticmethod
    def get_word_completer():
        if os.path.isfile(history_file):
            _file = open(history_file)
            history_list = _file.read().split('\n')
            history_list = [
                re.sub(r'#.*', '',  re.sub('^\+', '', i))
                for i in history_list
                ]
            return WordCompleter(list(set(history_list)), ignore_case=True)

    def loop(self, message="matlabette> "):
        try:
            print (Fore.BLUE)
            print(""" Matlabette, a tiny MATLAB clone.
 Type exit or press Ctrl + C / Ctrl + D to exit.
 Type help for help.""")
            print ()
            while True:
                line = self.prompt(message)
                self.eval(line)

        except (KeyboardInterrupt, EOFError):
            if self.context.variables:
                self.exit_prompt()

    def prompt(self, message):
        return prompt(
            message,
            history=self.history,
            lexer=MatlabLexer,
            completer=self.get_word_completer(),
            display_completions_in_columns=True,
            mouse_support=True
        )

    def exit_prompt(self):
        try:
            while True:
                option = self.prompt("Save the workspace? (y/n) ").lower()
                if option == 'y':
                    self.save()
                    break
                elif option == 'n':
                    raise KeyboardInterrupt
        except (KeyboardInterrupt, EOFError):
            print (Fore.YELLOW)
            print (" Workspace not saved")
            print ()

    def eval(self, line):
        if line.startswith("save "):
            filename = line.replace("save ", "")
            self.save(filename)
            return

        if line.startswith("load "):
            filename = line.replace("load ", "")
            self.load(filename)
            return

        tokens = Lexer.lex(line)
        try:
            parse_tree = Parser(tokens).parse()
            if parse_tree:
                output = self.context.evaluate(parse_tree)
                if output:
                    print(Fore.GREEN + output)

        except MatlabetteError as e:
            print(Fore.RED)
            print(" Error: " + e.message)
            print()

    def load(self, filename):
        print ()
        try:
            with open(filename, 'r') as f:
                print(Fore.BLUE + " Loading workspace from '{}'"
                      .format(os.path.abspath(filename)))
                input_line = f.readline()
                while input_line:
                    self.eval(input_line)
                    input_line = f.readline()
                print(Fore.BLUE + " Done")
        except IOError:
            print(Fore.RED + " Error: failed to open '{}'"
                  .format(os.path.abspath(filename)))
        print ()

#.........这里部分代码省略.........
开发者ID:andela-hthuo,项目名称:bc-6-matlabette,代码行数:103,代码来源:repl.py

示例4: OMV

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import evaluate [as 别名]
#context.push({})
print OMV("x")
print OMA(OMV("x"),[OMV("y"),1])


#from binding import OMBinding, lambdasym


context["x"] = 1

x = OMV("x")

y = OMV("y")

print context.evaluate(x)
print context.evaluateVariable(x)
print context.evaluate(y)
import cd.arith1 as arith1
context.addCDImplementation(arith1.implementation)
def test(expr):
    print "Original: ", expr
    print "Evaluated: ", context.evaluate(expr)
test(OMA(arith1.implementation.plus, [1,2]))
test(OMA(arith1.implementation.unary_minus, [10]))
test(OMA(arith1.implementation.times, [3,4]))
test(OMA(arith1.implementation.abs, [-123]))
print context.evaluate(OMA(arith1.implementation.plus, [1,2]))
application = OMA(OMS("plus", arith1.content), [1,2])

print context.evaluate(application)
开发者ID:Macaulay2,项目名称:Singular,代码行数:32,代码来源:tester.py

示例5: repr

# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import evaluate [as 别名]
                eval=True
            else:
                inputf=arg
                state=1
            continue
        if state==1:
            outputf=arg
            continue
        if state==2:
            print "argument ignored:", arg
    from context import Context
    #inputf=sys.argv[1]
    root=readFile(inputf)
    builder=OMFromXMLBuilder()
    context=Context()
    context.addCDImplementation(arith1.implementation2)
    doc=builder.build(root)
    if eval:
        doc=context.evaluate(doc)
    #import profile
    #profile.run('output=context.XMLEncodeObject(doc)','encodeprof')
    output=context.XMLEncodeObject(doc)
    try:
        out=open(outputf,"w")
    except NameError:
        print "no output file"
        sys.exit(1)
    out.write(output)
    out.close()
    #print repr(root.getAttribute("blabla"))
开发者ID:Macaulay2,项目名称:Singular,代码行数:32,代码来源:omxmlreader.py


注:本文中的context.Context.evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。