我可以从python脚本运行shell函数吗?

2024-04-25 13:19:15 发布

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

如果我的shell脚本中有某个函数,我可以从外部python脚本调用该函数吗?在


Tags: 函数脚本shell
1条回答
网友
1楼 · 发布于 2024-04-25 13:19:15

以下是一些参考资料,因为我不太清楚你想做什么:

Running Shell Commands

您可以使用Pythonsubprocess模块:

from subprocess import call
call(["ls", "-l"])

或者,如果您试图从shell脚本内部运行一个特定的函数,那么在Python中重新编写该函数的代码会更加明智。类似的SO问题可以在这里找到:

How to call a shell script function/variable from python?

相关问题 更多 >

    热门问题