Hard to understand 'eval'

TheSaint fc14301589 at icqmail.com
Sun Jun 15 11:45:12 CEST 2008


On 06:34, domenica 15 giugno 2008 Dennis Lee Bieber wrote:

>>         for nn in stn_items:

> I already see a syntax error when viewing that in Agent... A missing
> indent level under the "for"

The program don't complain wrong indentation, I mostly sure a wrong
copy-paste error.
Error doesn't come up there.

> . You also don't need the continue if you change the second if into elif.
> 
My mistake, I thought that was improving the loop.

is it an if....elif....elif probing only the first matching case and drop the
remaining checks?

> And what type of structure is "cfl"?

You got close, that's a dictionary of dictionaries and I'm trying to updating
it.

> wonder what this mysterious _append() function is supposed to be doing;
Append() is a conventional name regarding a file logging.
There would be an option to set a quota of bytes size.

> Huh... I presume you mean to convert from a text decimal

it isn't so, the function look at the string to see if ending by K or M,
which means Kbytes or Mbytes. It'll return the decimal conversion.
If the value is set as boolean value, then it will do appending to the log
when it True or stop appending when there's a quota.

def _append(c, v):
    RE_BYTE= re.compile(r'^[\d]+(k|m)?$',re.I)
    # any number of digit followed by 0 or 1  (k or m), case insensitive
    chkbool(v)
    if isinstance(v,bool):
        c['append']= v
        return c
    if RE_BYTE.match(value):
        k= 1024; M= k * k; v= int(value[:-1])
        if value[-1:] == 'k': v= v * k
        if value[-1:] == 'm': v= v * m
        c['append']= v
    return c

All the code could be download at my web site ;)
But this here it's a bit new concept.
-- 
Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html



More information about the Python-list mailing list