"Eval Calculator" by simon

Rating: (0 votes)

Report this Script

Name: Eval Calculator
Uploaded By: simon
Date Created: May 2, 2009 3:35 a.m.
Date Modified: May 2, 2009 3:35 a.m.
Description: This script takes the expression you have selected in the editor and runs it through the Python evaluator. Useful for checking maths or logic expressions.
Num Views: 362
Num Downloads: 131

Contents

Download this script

import pn, scintilla

@script("Calculator")
def DoMaths():
    s = scintilla.Scintilla(pn.CurrentDoc())

    if s.SelectionEnd - s.SelectionStart < 1:
        return

    sel = s.SelText

    i = eval(sel)
    if type(i) in [int, float, complex]:
        pn.AddOutput(str(i))

Comments: