File: expr.py

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,880 kB
  • sloc: cpp: 1,442,792; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 103; objc: 17
file content (29 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Evalues a tcl expr expression."""
import math

def expr(caller_globals_dict, caller_localvars_dict, arguments):
    """the arguments to expr in tcl are passed as individual arguments to this
    method.
    eg [expr sin(20)*$a] becomes expr.expr("sin","(","20",")","*", a)"""
    eval_str = "eval(\"\"\""
    for arg in arguments:
        if arg in caller_localvars_dict.keys():
            #arg is a local variable. First, get its value
            arg = caller_localvars_dict[arg]
        if type(arg) == type("string"):
            #this will obtain value in the variable.
            if arg in dir(math):
                eval_str += "math.%s" % arg
            else:
                if arg == "(":
                    eval_str +=    arg
                else:
                    if arg.strip() == "double":
                        arg = "float" #tcl double is python float
                    eval_str +=    " " + arg
            continue
        eval_str += " " + `arg`
    eval_str += "\"\"\")"
    #print "eval_str : %s" % eval_str
    return eval(eval_str, caller_globals_dict, caller_localvars_dict)