将param传递给sh中的Python脚本

2024-06-16 10:45:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要将param传递给文件sh中的python函数

我的数组是这样的:

$ echo $myarr 
0, 17, 25, 28, 11, 19, 15, 2, 2, 2, 23, 27, 27, 8, 24, 15, 7, 13, 18, 27, 1, 23, 30, 21, 26, 19, 17, 27, 31, 25, 19, 6, 13

python函数是like,它的输出是

$ python -c 'import bech32; print bech32.bech32_create_checksum("tb", ['$myarr'] )'
  File "<string>", line 1
    import bech32; print bech32.bech32_create_checksum("tb", [0,
                                                               ^
SyntaxError: unexpected EOF while parsing

如果我使用数组(不带变量),它可以工作

$ python -c 'import bech32; print bech32.bech32_create_checksum("tb", [0, 17, 25, 28, 11, 19, 15, 2, 2, 2, 23, 27, 27, 8, 24, 15, 7, 13, 18, 27, 1, 23, 30, 21, 26, 19, 17, 27, 31, 25, 19, 6, 13] )'
[10, 9, 20, 29, 27, 15]

Here您可以看到python函数


Tags: 文件函数importechoparamshcreate数组
1条回答
网友
1楼 · 发布于 2024-06-16 10:45:15

将单引号与python cmd一起使用是错误的,因为它打断了行。由此产生了第一个错误。除此之外,要将param传递给python cmd,可以执行以下操作:

python3 -c 'import sys; print(sys.argv[1])' "Now it should work"

相关问题 更多 >