Creating unique combinations from lists

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Jan 17 18:36:27 EST 2008


On Thu, 17 Jan 2008 10:44:51 -0600, Reedick, Andrew wrote:

>> -----Original Message-----
>> From: Tim Chase [mailto:python.list at tim.thechases.com] Sent: Thursday,
>> January 17, 2008 10:30 AM To: Reedick, Andrew
>> Cc: breal; python-list at python.org; martin at v.loewis.de Subject: Re:
>> Creating unique combinations from lists
>> 
>> Yick...a nice demo of the power of eval, but definitely filed under the
>> "Hack" heading
> 
> You hurt my feeling.  *sniffle*  Given how late python
> compiles/evaluates code blocks, I'm thinking that eval() is less hack
> and more paradigm ..err.. pythonic.  ;-)

I see your smiley, but even so, do you have any idea how many times eval 
is used in the standard library? Not very often.

$ pwd
/usr/lib/python2.5
$ grep -r "eval(.*)" *.py | wc -l
20

Some of those twenty matches are false positives. I manually inspected 
them, and by my count there are just ten actual uses of eval:

bdb.py:                return eval(expr, globals, locals)
dumbdbm.py:                key, pos_and_siz_pair = eval(line)
gettext.py:    return eval('lambda n: int(%s)' % plural)
gopherlib.py:                _type_to_name_map[eval(name)] = name[2:]
mhlib.py:    def do(s): print s; print eval(s)
os.py:        eval(name)
pdb.py:                x = eval(arg, {}, {})
rexec.py:        return eval(code, m.__dict__)
rlcompleter.py:        object = eval(expr, self.namespace)
warnings.py:            cat = eval(category)


I haven't made any effort to determine how many of them are gaping great 
big security holes.



-- 
Steven



More information about the Python-list mailing list