benim piton kodu genellikle şuna benzer:Kuru çalışma yöntemi? Şu anda
...
if not dry_run:
result = shutil.copyfile(...)
else:
print " DRY-RUN: shutil.copyfile(...) "
...
şimdi kuru koşucu yöntemiyle gibi bir şey yazma düşünmek
: Sonuç
def dry_runner(cmd, dry_run, message, before="", after=""):
if dry_run:
print before + "DRY-RUN: " + message + after
# return execute(cmd)
Ama cmd ilk çalıştırılacak ve olduğu dry_runner yöntemine verildi.
Böyle bir yöntemi pythonik şekilde nasıl kodlayabilirim? işlevselliği çalışır
def execute(func, *args):
print 'before', func
if not dry:
func(*args)
print 'after', func
>>> execute(shutil.copyfile, 'src', 'dst')