【问题标题】:Passing list from perl to Python and check return value将列表从 perl 传递到 Python 并检查返回值
【发布时间】:2021-01-24 11:29:27
【问题描述】:

我在 perl 中编写了以下脚本并尝试通过 python。

输入:D1 和 D2 是数组,plotanalysis 是 python 脚本

my @D1=([],[]);
my @D2=([],[]);
my $cmd="plotanalysis -d1 @D1 -d2 @D2";
print STDERR "***Info : plotanalysis command $cmd\n";
if(system($cmd)!=0)
{
  print STDERR "plotanalysis did not run";
}

期待:我期待数组将传递给 python 脚本但得到以下信息

下一行

plotanalysis command plotanalysis -d1 ARRAY(0x873b58) ARRAY(0x873b88) -d2 ARRAY(0xa3ffa0) ARRAY(0xa3ffd0)
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `plotanalysis -d1 ARRAY(0x873b58) ARRAY(0x873b88) -d2 ARRAY(0xa3ffa0) ARRAY(0xa3ffd0)'

解决问题的任何输入/建议。我还需要从 python 脚本中捕获返回值。请问怎么处理?

在 python 脚本中,我将其设为字符串

def parse_args(args):
    """Parse the argument"""
    parser = argparse.ArgumentParser(description='check function',
                                     epilog="""
                                     for reporting any issue""")
    parser.add_argument('-d1', '-data1', dest='data_1', required=True,
                        nargs = "*",
                        help = "x and y data for calculation")
    parser.add_argument('-d2', '-data2', dest='data_2', required=True,
                        nargs = "*",
                        help = "x and y data for calculation")
    args = parser.parse_args(args)
    return args
def main(args):
    """Invoke main functionality"""
    print (args)
    

if __name__ == "__main__":
    sys.exit(main(parse_args(sys.argv[1:])))

【问题讨论】:

    标签: python perl


    【解决方案1】:

    我已经完成了以下更新,这有助于我获得所需的价值

    my $cmd="plotanalysis -d1 '@{$D1[1]}' -d2 '@{$D2[1]}'";
    print STDERR "***Info : plotanalysis command $cmd\n";
    if(system($cmd)!=0)
    {
      print STDERR "plotanalysis did not run";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多