python - 将变量传递给函数时Python子进程无效语法
问题描述
我有一个 python 脚本,想从中调用一个子进程。以下示例完全可以正常工作:
脚本1:
from subprocess import Popen
p = Popen('python Script2.py', shell=True)
脚本2:
def execute():
print('works!')
execute()
但是,只要我想将变量传递给函数,就会出现以下错误:
def execute(random_variable: str):
SyntaxError: invalid syntax
脚本1:
from subprocess import Popen
p = Popen('python Script2.py', shell=True)
脚本2:
def execute(random_variable: str):
print(random_variable)
execute(random_variable='does not work')
有谁知道为什么会这样?在网上找不到任何关于它的东西:(
解决方案
好的,伙计们,找到了解决方案:如果你在 mac 上,只需使用 'python3' 而不是 'python' ...:
p = Popen('python3 Script2.py', shell=True)
感谢您的帮助!:)
推荐阅读
- javascript - Put a condition in java script
- javascript - jQuery isFunction 发出错误
- python - Pandas Dataframe:在 12 小时内删除带有 DateTime 的行
- xpath - 使用具有强标记的唯一标识符的按钮的 XPath
- react-native - Export default connect and export default class (FluidNavigator)
- r - 将 strsplit 应用于多列
- c# - Visible Grid line in the application
- sql - 查询以获取日期范围内的计数、小计和总计
- python - 如何在引号中传递循环索引的值
- apache-kafka - 如果我们通过 Apache Kafka 设置 RDBMS 复制,FK(外键)会出现问题吗?