Changeset 3587:718dc8910350 in orange


Ignore:
Timestamp:
04/25/07 01:08:08 (7 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
4a1c6280429b26fb3f3a58fc4ef09161c86f0dc2
Message:
  • attributes with non-identifier-like names can now be used if quoted
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Prototypes/OWFeatureConstructor.py

    r3586 r3587  
    1010import OWGUI, math, re 
    1111 
    12 re_identifier = re.compile("(?<=\W)[a-zA-Z_]\w*(?=(\Z|\W))") 
     12re_identifier = re.compile(r'((?<=\W)[a-zA-Z_]\w*(?=(\Z|\W)))|("[^"]+")') 
    1313 
    1414def identifier_replacer(id): 
    1515    id = id.group() 
    16     return id in math.__dict__ and id or "_ex['%s']" % id 
     16    if id in math.__dict__: 
     17        return id 
     18    if id[0] == id[-1] == '"': 
     19        return "_ex[%s]" % id 
     20    else: 
     21        return "_ex['%s']" % id 
    1722 
    1823class AttrComputer: 
     
    2227    def __call__(self, ex, weight): 
    2328        try: 
    24             print eval(self.expression, math.__dict__, {"_ex": ex}) 
    2529            return float(eval(self.expression, math.__dict__, {"_ex": ex})) 
    2630        except: 
     
    6367            attrname = "T%04i" % t 
    6468 
    65  
    6669        exp = re_identifier.sub(identifier_replacer, " "+self.expression) 
    67         print exp 
    6870        newattr = orange.FloatVariable(str(attrname), getValueFrom = AttrComputer(exp)) 
    6971 
Note: See TracChangeset for help on using the changeset viewer.