我移植从Perl来Python的一些代码,和我移动的功能之一执行以下操作:裹在Python中的函数提供一个额外的布尔
sub _Run($verbose, $cmd, $other_stuff...)
{
...
}
sub Run
{
_Run(1, @_);
}
sub RunSilent
{
_Run(0, @_);
}
这样做的Python,我天真地认为我可以做到以下几点:
def _Run(verbose, cmd, other_stuff...)
...
def Run(*args)
return _Run(True, args);
def RunSilent
return _Run(False, args);
但这不起作用,因为args是作为数组/元组传递的。为了使它工作,我做了以下工作:
def _Run(verbose, cmd, other_stuff...)
...
def Run(*args)
return _Run(True, ','.join(args));
def RunSilent
return _Run(False, ','.join(args));
但这看起来有点丑。有没有更好的办法?
谢谢。我确实结束了这个: def run(cmd,other_stuff,silent = False): 有时候,在移植这个Perl的东西时,我太习惯了,不要停下来想想我该怎么做在Python中。 – Cliff 2010-08-30 18:51:24