Hard to understand 'eval'

TheSaint fc14301589 at icqmail.com
Sat Jun 14 04:31:35 EDT 2008


Hi,

It seems to be strange that give me syntax error inside an eval statement.
I'm looking at it carefully but I can't see any flaw.

Here it's part of the code:

        for nn in stn_items:
        value= eval('cp.%s' %nn)
        if value and (nn in 'log, trash, multithread, verbose, download'):
            cfl[wchkey][nn]= chkbool(value)
            continue
        if value:
            cnfg= 'cfl[wchkey][nn]= _%s(value)' %nn
            eval(cnfg)

And the output on pdb:

(Pdb) p cnfg
'cfl[wchkey][nn]=_append(value)'
(Pdb) p cfl[wchkey][nn]
False
(Pdb) eval('cfl[wchkey][nn]= _append(value)')
*** SyntaxError: invalid syntax (<string>, line 1)
(Pdb) p value
'230k'
(Pdb) p nn
'append'

Obviously I've an _append() function to convert into decimal the given value.

Other "eval" before this not issuing problems and also rather complicated,
but I'm not seeing the error here.
I'd like to study a class that might get a string and convert it into
function, once it's found inside the program.

-- 
Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html



More information about the Python-list mailing list