Pls. help me recreate shell trick

Eddie Corns eddie at holyrood.ed.ac.uk
Mon Nov 26 11:16:20 EST 2001


Nicola Musatti <objectway at divalsim.it> writes:

>Thanks to both Fernando and Daniel for your suggestions. However, I
>probably didn't explain myself very clearly. My aim is not only to
>provide display only, debug mode for external commands, but also for
>possibly disrupting Python statements. One example could be:

>import shutil
>shutil.copyfile(src,dest)

A very simple minded solution:

def protect (func, *args):
    if debug:
        print '!!Calling',func.__name__,'with',args
    else:
        apply (func, args)


Then just use:

  protect (shutil.copy, src, dest)

after setting debug.  It would be trivial to add code to ask the user whether
to go ahead and do the command as well.

Eddie



More information about the Python-list mailing list