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

Skip Montanaro skip at
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:

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

Skip Montanaro (skip at -
Boycott Netflix - they spam -

More information about the Python-list mailing list