Created a "file" like command in python (see man 4 magic) and face a showstoper bug

Skip Montanaro skip at pobox.com
Mon Jun 3 15:22:14 EDT 2002


    Thomas> The code causing problem is :

    Thomas> if replace:
    Thomas>   try:
    Thomas>     mime = mime % replace
    Thomas>   except:
    Thomas>     pass

    Thomas> In both case mime is containing the string "%d." and replace is
    Thomas> in both case of type int and valued 1 and 0.

    Thomas> Any idea ?

My guess is that either mime or replace aren't what you think they are and
your catch-all except clause is masking an error in your code.  I suggest
you make the except clause more explicit (what problems are you prepared to
handle?) and/or print out mime and replace before executing the % operator:

    try:
        print (mime, replace)
        mime = mime % replace
    except StuffIKnowHowToRecoverFrom:
        recover_from_nasty_stuff()

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)
Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html






More information about the Python-list mailing list