Is it possible to 'compile' a script?

sismex01 at hebmex.com sismex01 at hebmex.com
Fri Oct 4 13:02:44 EDT 2002


Bwaaaahahahahaah!!!

Thanks Alex, you've really made my day!!! :-D

>>> # Compile simple throwaway expression.
>>> xxx = compile("a > 2 and 5 < b < 10 and c < 0", "---", "eval")
>>> dir(xxx)
['__class__', '__cmp__', '__delattr__', '__getattribute__', '__hash__',
 '__init__', '__new__', '__reduce__', '__repr__', '__setattr__', '__str__',
 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename',
 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name',
 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
>>> xxx.co_varnames
()
>>> xxx.co_names
('a', 'b', 'c')
>>> # Hah! Gotcha!
>>> eval(xxx, {}, {"a":1, "b":4, "c":-4})
0
>>> eval(xxx, {}, {"a":3, "b":7, "c":-4})
1


Like I said, THANKYOU VERY VERY VERY MUCH!

:-)

-gustavo

















More information about the Python-list mailing list