Hard to understand 'eval'

TheSaint fc14301589 at icqmail.com
Sun Jun 15 21:55:32 EDT 2008


On 05:05, 16-6- 2008 Dennis Lee Bieber wrote:

>>     # any number of digit followed by 0 or 1  (k or m), case insensitive
> 
> I don't do regular expressions... and the comment doesn't help
> "digit followed by 0 or 1", when 0/1 ARE digits themselves...
That means either none or one letter, of which k or m are allowed.
 
> c is a mutable object; you don't have to return it; the change is
> seen by anything holding a reference to the object.

C is a dictionary, it might be omitted, but I'm still not sure if will lose
its state.
 
> Again, as c is mutable, it doesn't need to be returned.
 
> Apparently

Not so apparent, it's doing that, buddy :)

> v = v.strip().lower()
regexp did a fine check and case insensitive, but I like your idea too.
 
> Biggest flaw, in my mind... You are using ONE identifier to control
> TWO meanings... a boolean On/Off control AND an integer size limit
> control.

That occupy only small variable and as long as python can accept anything not
zero, false or none for an _if_ condition, that might be allowable, I think.
Then if not zero will mean the log will be *appended* to an existing file and
if the value is something that can be converted in decimal value, then this
will set the quota for the log file, as well.
Here below dbg is the log file and if it isn't None then s a valid file path
should work.

    dbg= sttng['log']; mode= 'w' # normally write, it writes new
    try:
        if sttng['append'] > Path.getsize(dbg): mode= 'a'
    except (OSError, TypeError): # found a boolean or dbg is new file
        pass

So 5 line of code can do me the job smartly, I think ;)

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



More information about the Python-list mailing list